1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet,
int& nChangePosInOut, std::string& strFailReason, const CCoinControl* coinControl, bool sign)
{
CAmount nValue = 0;
int nChangePosRequest = nChangePosInOut;
unsigned int nSubtractFeeFromAmount = 0;
for (const auto& recipient : vecSend)
{
if (nValue < 0 || recipient.nAmount < 0)
{
strFailReason = _("Transaction amounts must not be negative");
return false;
}
nValue += recipient.nAmount;

if (recipient.fSubtractFeeFromAmount)
nSubtractFeeFromAmount++;
}
if (vecSend.empty())
{
strFailReason = _("Transaction must have at least one recipient");
return false;
}

##首先对函数参数进行介绍:

  1. vecSend: 是recipient的数组 recipient = {scriptPubKey, nValue, fSubtractFeeFromAmount},scriptPubkey是包含了目标公钥的脚本 nValue是要发送给目标的金额,fSubtractFeeFromAmount是一个Bool型数据,代表是否要从目标账户中扣除小费
  2. wtxNew:
  3. reservekey: 可以看做一个key pool,从中可以取出密钥
  4. nFeeRet: 已经凑集的小费金额
  5. nChangePosInOut: change(零钱)在vout中的下标
  6. sign: bool型变量,代表是否要签名产生sigdata