Skip to content

Commit

Permalink
Fix method to use optional parameters json
Browse files Browse the repository at this point in the history
  • Loading branch information
vctt94 committed Jul 12, 2018
1 parent 7401a62 commit 84751bc
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 59 deletions.
26 changes: 6 additions & 20 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions internal/rpchelp/helpdescs_en_US.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,16 @@ var helpDescsEnUS = map[string]string{
"dumpprivkey--result0": "The WIF-encoded private key",

// FundRawTransactionCmd help.
"fundrawtransaction--synopsis": "Add inputs to a transaction until it has enough in value to meet its out value.",
"fundrawtransaction-hexstring": "The raw transaction encoded as a hexadecimal string",
"fundrawtransaction-fundaccount": "The account string which will fund the transaction",
"fundrawtransaction-changeaccount": "Account name the change will be send to (default=\"default\")",
"fundrawtransaction-lockunspents": "Lock selected unspent outputs",
"fundrawtransaction-feerate": "Set a specific fee rate in DCR/kB",
"fundrawtransaction-requiredconfirmations": "Number of blocks to confirm the transaction",
"fundrawtransaction--synopsis": "Add inputs to a transaction until it has enough in value to meet its out value.",
"fundrawtransaction-hexstring": "The raw transaction encoded as a hexadecimal string",
"fundrawtransaction-fundaccount": "The account string which will fund the transaction",
"fundrawtransaction-options": "The optional inputs to fund a raw transaction",

// FundRawTransactionOptions
"fundrawtransactionoptions-changeaccount": "Account name the change will be send to (default=\"default\")",
"fundrawtransactionoptions-lockunspents": "Lock selected unspent outputs",
"fundrawtransactionoptions-feerate": "Set a specific fee rate in DCR/kB",
"fundrawtransactionoptions-requiredconfirmations": "Number of blocks to confirm the transaction",

// FundRawTransactionResult help.
"fundrawtransactionresult-hex": "The resulting raw transaction (hex-encoded string)",
Expand Down
64 changes: 34 additions & 30 deletions rpc/legacyrpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,8 @@ func dumpPrivKey(s *Server, icmd interface{}) (interface{}, error) {
return key, nil
}

// fundRawTransaction handles a fundrawtransaction request by funding a raw
// transaction and returning its raw hex and its fee.
func fundRawTransaction(s *Server, icmd interface{}) (interface{}, error) {
cmd := icmd.(*dcrjson.FundRawTransactionCmd)
w, ok := s.walletLoader.LoadedWallet()
Expand All @@ -518,21 +520,9 @@ func fundRawTransaction(s *Server, icmd interface{}) (interface{}, error) {
}
return nil, err
}

// use provided fee per Kb if specified
feePerKb := w.RelayFee()
if cmd.FeeRate != nil {
var err error
feePerKb, err = dcrutil.NewAmount(*cmd.FeeRate)
if err != nil {
return nil, rpcError(dcrjson.ErrRPCInvalidParameter, err)
}
}
// use provided required confirmations if specified
requiredConfs := int32(1)
if cmd.RequiredConfirmations != nil {
requiredConfs = *cmd.RequiredConfirmations
}
changeAccount := uint32(0)

var mtx wire.MsgTx
decodedTx, err := hex.DecodeString(cmd.HexString)
Expand All @@ -554,25 +544,14 @@ func fundRawTransaction(s *Server, icmd interface{}) (interface{}, error) {
Account: accNumber,
RequiredConfirmations: requiredConfs,
}
totalAmount, inputs, _, err := w.SelectInputs(dcrutil.Amount(amount), policy)
inputDetails, err := w.SelectInputs(dcrutil.Amount(amount), policy)
if err != nil {
return nil, err
}

mtx.TxIn = append(mtx.TxIn, inputs...)
mtx.TxIn = append(mtx.TxIn, inputDetails.Inputs...)

// use provided change account if specified
// use default account otherwise
changeAccount := uint32(0)
if cmd.ChangeAccount != nil {
changeAccount, err = w.AccountNumber(*cmd.ChangeAccount)
if err != nil {
if errors.Is(errors.NotExist, err) {
return nil, errAccountNotFound
}
return nil, err
}
}
totalAmount := inputDetails.Amount
if totalAmount > amount {
addr, err := w.NewChangeAddress(changeAccount)
if err != nil {
Expand All @@ -587,9 +566,34 @@ func fundRawTransaction(s *Server, icmd interface{}) (interface{}, error) {
mtx.TxOut = append(mtx.TxOut, changeOut)
}

if *cmd.LockUnspents {
for _, txIn := range mtx.TxIn {
w.LockOutpoint(txIn.PreviousOutPoint)
if cmd.Options != nil {
// use provided fee per Kb if specified
if cmd.Options.FeeRate != nil {
var err error
feePerKb, err = dcrutil.NewAmount(*cmd.Options.FeeRate)
if err != nil {
return nil, rpcError(dcrjson.ErrRPCInvalidParameter, err)
}
}
// use provided required confirmations if specified
if cmd.Options.RequiredConfirmations != nil {
requiredConfs = *cmd.Options.RequiredConfirmations
}
if cmd.Options.LockUnspents != nil && *cmd.Options.LockUnspents {
for _, txIn := range mtx.TxIn {
w.LockOutpoint(txIn.PreviousOutPoint)
}
}
// use provided change account if specified
// use default account otherwise
if cmd.Options.ChangeAccount != nil {
changeAccount, err = w.AccountNumber(*cmd.Options.ChangeAccount)
if err != nil {
if errors.Is(errors.NotExist, err) {
return nil, errAccountNotFound
}
return nil, err
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions rpc/legacyrpc/rpcserverhelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func helpDescsEnUS() map[string]string {
"consolidate": "consolidate inputs (\"account\" \"address\")\n\nConsolidate n many UTXOs into a single output in the wallet.\n\nArguments:\n1. inputs (numeric, required) Number of UTXOs to consolidate as inputs\n2. account (string, optional) Optional: Account from which unspent outputs are picked. When no address specified, also the account used to obtain an output address.\n3. address (string, optional) Optional: Address to pay. Default is obtained via getnewaddress from the account's address pool.\n\nResult:\n\"value\" (string) Transaction hash for the consolidation transaction\n",
"createmultisig": "createmultisig nrequired [\"key\",...]\n\nGenerate a multisig address and redeem script.\n\nArguments:\n1. nrequired (numeric, required) The number of signatures required to redeem outputs paid to this address\n2. keys (array of string, required) Pubkeys and/or pay-to-pubkey-hash addresses to partially control the multisig address\n\nResult:\n{\n \"address\": \"value\", (string) The generated pay-to-script-hash address\n \"redeemScript\": \"value\", (string) The script required to redeem outputs paid to the multisig address\n} \n",
"dumpprivkey": "dumpprivkey \"address\"\n\nReturns the private key in WIF encoding that controls some wallet address.\n\nArguments:\n1. address (string, required) The address to return a private key for\n\nResult:\n\"value\" (string) The WIF-encoded private key\n",
"fundrawtransaction": "fundrawtransaction \"hexstring\" \"fundaccount\" (\"changeaccount\" lockunspents=false feerate requiredconfirmations)\n\nAdd inputs to a transaction until it has enough in value to meet its out value.\n\nArguments:\n1. hexstring (string, required) The raw transaction encoded as a hexadecimal string\n2. fundaccount (string, required) The account string which will fund the transaction\n3. changeaccount (string, optional) Account name the change will be send to (default=\"default\")\n4. lockunspents (boolean, optional, default=false) Lock selected unspent outputs\n5. feerate (numeric, optional) Set a specific fee rate in DCR/kB\n6. requiredconfirmations (numeric, optional) Number of blocks to confirm the transaction\n\nResult:\n{\n \"hex\": \"value\", (string) The resulting raw transaction (hex-encoded string)\n \"fee\": n.nnn, (numeric) Fee in DCR the resulting transaction pays\n} \n",
"fundrawtransaction": "fundrawtransaction \"hexstring\" \"fundaccount\" ({\"changeaccount\":changeaccount,\"lockunspents\":lockunspents,\"feerate\":feerate,\"requiredconfirmations\":requiredconfirmations})\n\nAdd inputs to a transaction until it has enough in value to meet its out value.\n\nArguments:\n1. hexstring (string, required) The raw transaction encoded as a hexadecimal string\n2. fundaccount (string, required) The account string which will fund the transaction\n3. options (object, optional) The optional inputs to fund a raw transaction\n{\n \"changeaccount\": \"value\", (string) Account name the change will be send to (default=\"default\")\n \"lockunspents\": true|false, (boolean) Lock selected unspent outputs\n \"feerate\": n.nnn, (numeric) Set a specific fee rate in DCR/kB\n \"requiredconfirmations\": n, (numeric) Number of blocks to confirm the transaction\n} \n\nResult:\n{\n \"hex\": \"value\", (string) The resulting raw transaction (hex-encoded string)\n \"fee\": n.nnn, (numeric) Fee in DCR the resulting transaction pays\n} \n",
"getaccount": "getaccount \"address\"\n\nDEPRECATED -- Lookup the account name that some wallet address belongs to.\n\nArguments:\n1. address (string, required) The address to query the account for\n\nResult:\n\"value\" (string) The name of the account that 'address' belongs to\n",
"getaccountaddress": "getaccountaddress \"account\"\n\nDEPRECATED -- Returns the most recent external payment address for an account that has not been seen publicly.\nA new address is generated for the account if the most recently generated address has been seen on the blockchain or in mempool.\n\nArguments:\n1. account (string, required) The account of the returned address\n\nResult:\n\"value\" (string) The unused address for 'account'\n",
"getaddressesbyaccount": "getaddressesbyaccount \"account\"\n\nDEPRECATED -- Returns all addresses strings controlled by a single account.\n\nArguments:\n1. account (string, required) Account name to fetch addresses for\n\nResult:\n[\"value\",...] (array of string) All addresses controlled by 'account'\n",
Expand Down Expand Up @@ -87,4 +87,4 @@ var localeHelpDescs = map[string]func() map[string]string{
"en_US": helpDescsEnUS,
}

var requestUsages = "accountaddressindex \"account\" branch\naccountsyncaddressindex \"account\" branch index\naddmultisigaddress nrequired [\"key\",...] (\"account\")\nconsolidate inputs (\"account\" \"address\")\ncreatemultisig nrequired [\"key\",...]\ndumpprivkey \"address\"\ngetaccount \"address\"\ngetaccountaddress \"account\"\ngetaddressesbyaccount \"account\"\ngetbalance (\"account\" minconf=1)\ngetbestblockhash\ngetblockcount\ngetinfo\ngetmasterpubkey (\"account\")\ngetmultisigoutinfo \"hash\" index\ngetnewaddress (\"account\" \"gappolicy\")\ngetrawchangeaddress (\"account\")\ngetreceivedbyaccount \"account\" (minconf=1)\ngetreceivedbyaddress \"address\" (minconf=1)\ngettickets includeimmature\ngettransaction \"txid\" (includewatchonly=false)\ngetvotechoices\nhelp (\"command\")\nimportprivkey \"privkey\" (\"label\" rescan=true scanfrom)\nimportscript \"hex\" (rescan=true scanfrom)\nkeypoolrefill (newsize=100)\nlistaccounts (minconf=1)\nlistlockunspent\nlistreceivedbyaccount (minconf=1 includeempty=false includewatchonly=false)\nlistreceivedbyaddress (minconf=1 includeempty=false includewatchonly=false)\nlistsinceblock (\"blockhash\" targetconfirmations=1 includewatchonly=false)\nlisttransactions (\"account\" count=10 from=0 includewatchonly=false)\nlistunspent (minconf=1 maxconf=9999999 [\"address\",...])\nlockunspent unlock [{\"amount\":n.nnn,\"txid\":\"value\",\"vout\":n,\"tree\":n},...]\nredeemmultisigout \"hash\" index tree (\"address\")\nredeemmultisigouts \"fromscraddress\" (\"toaddress\" number)\nrescanwallet (beginheight=0)\nrevoketickets\nsendfrom \"fromaccount\" \"toaddress\" amount (minconf=1 \"comment\" \"commentto\")\nsendmany \"fromaccount\" {\"address\":amount,...} (minconf=1 \"comment\")\nsendtoaddress \"address\" amount (\"comment\" \"commentto\")\nsendtomultisig \"fromaccount\" amount [\"pubkey\",...] (nrequired=1 minconf=1 \"comment\")\nsettxfee amount\nsetvotechoice \"agendaid\" \"choiceid\"\nsignmessage \"address\" \"message\"\nsignrawtransaction \"rawtx\" ([{\"txid\":\"value\",\"vout\":n,\"tree\":n,\"scriptpubkey\":\"value\",\"redeemscript\":\"value\"},...] [\"privkey\",...] flags=\"ALL\")\nsignrawtransactions [\"rawtx\",...] (send=true)\nstartautobuyer \"account\" \"passphrase\" (balancetomaintain maxfeeperkb maxpricerelative maxpriceabsolute \"votingaddress\" \"pooladdress\" poolfees maxperblock)\nstopautobuyer\nsweepaccount \"sourceaccount\" \"destinationaddress\" (requiredconfirmations feeperkb)\nvalidateaddress \"address\"\nverifymessage \"address\" \"signature\" \"message\"\nversion\nwalletlock\nwalletpassphrase \"passphrase\" timeout\nwalletpassphrasechange \"oldpassphrase\" \"newpassphrase\"\ncreatenewaccount \"account\"\nexportwatchingwallet (\"account\" download=false)\ngetbestblock\ngetunconfirmedbalance (\"account\")\nlistaddresstransactions [\"address\",...] (\"account\")\nlistalltransactions (\"account\")\nrenameaccount \"oldaccount\" \"newaccount\"\nwalletislocked\nwalletinfo\npurchaseticket \"fromaccount\" spendlimit (minconf=1 \"ticketaddress\" numtickets \"pooladdress\" poolfees expiry \"comment\" ticketfee)\ngeneratevote \"blockhash\" height \"tickethash\" votebits \"votebitsext\"\ngetstakeinfo\ngetticketfee\nsetticketfee fee\ngetwalletfee\naddticket \"tickethex\"\nlistscripts\nstakepooluserinfo \"user\"\nticketsforaddress \"address\""
var requestUsages = "accountaddressindex \"account\" branch\naccountsyncaddressindex \"account\" branch index\naddmultisigaddress nrequired [\"key\",...] (\"account\")\nconsolidate inputs (\"account\" \"address\")\ncreatemultisig nrequired [\"key\",...]\ndumpprivkey \"address\"\nfundrawtransaction \"hexstring\" \"fundaccount\" ({\"changeaccount\":changeaccount,\"lockunspents\":lockunspents,\"feerate\":feerate,\"requiredconfirmations\":requiredconfirmations})\ngetaccount \"address\"\ngetaccountaddress \"account\"\ngetaddressesbyaccount \"account\"\ngetbalance (\"account\" minconf=1)\ngetbestblockhash\ngetblockcount\ngetinfo\ngetmasterpubkey (\"account\")\ngetmultisigoutinfo \"hash\" index\ngetnewaddress (\"account\" \"gappolicy\")\ngetrawchangeaddress (\"account\")\ngetreceivedbyaccount \"account\" (minconf=1)\ngetreceivedbyaddress \"address\" (minconf=1)\ngettickets includeimmature\ngettransaction \"txid\" (includewatchonly=false)\ngetvotechoices\nhelp (\"command\")\nimportprivkey \"privkey\" (\"label\" rescan=true scanfrom)\nimportscript \"hex\" (rescan=true scanfrom)\nkeypoolrefill (newsize=100)\nlistaccounts (minconf=1)\nlistlockunspent\nlistreceivedbyaccount (minconf=1 includeempty=false includewatchonly=false)\nlistreceivedbyaddress (minconf=1 includeempty=false includewatchonly=false)\nlistsinceblock (\"blockhash\" targetconfirmations=1 includewatchonly=false)\nlisttransactions (\"account\" count=10 from=0 includewatchonly=false)\nlistunspent (minconf=1 maxconf=9999999 [\"address\",...])\nlockunspent unlock [{\"amount\":n.nnn,\"txid\":\"value\",\"vout\":n,\"tree\":n},...]\nredeemmultisigout \"hash\" index tree (\"address\")\nredeemmultisigouts \"fromscraddress\" (\"toaddress\" number)\nrescanwallet (beginheight=0)\nrevoketickets\nsendfrom \"fromaccount\" \"toaddress\" amount (minconf=1 \"comment\" \"commentto\")\nsendmany \"fromaccount\" {\"address\":amount,...} (minconf=1 \"comment\")\nsendtoaddress \"address\" amount (\"comment\" \"commentto\")\nsendtomultisig \"fromaccount\" amount [\"pubkey\",...] (nrequired=1 minconf=1 \"comment\")\nsettxfee amount\nsetvotechoice \"agendaid\" \"choiceid\"\nsignmessage \"address\" \"message\"\nsignrawtransaction \"rawtx\" ([{\"txid\":\"value\",\"vout\":n,\"tree\":n,\"scriptpubkey\":\"value\",\"redeemscript\":\"value\"},...] [\"privkey\",...] flags=\"ALL\")\nsignrawtransactions [\"rawtx\",...] (send=true)\nstartautobuyer \"account\" \"passphrase\" (balancetomaintain maxfeeperkb maxpricerelative maxpriceabsolute \"votingaddress\" \"pooladdress\" poolfees maxperblock)\nstopautobuyer\nsweepaccount \"sourceaccount\" \"destinationaddress\" (requiredconfirmations feeperkb)\nvalidateaddress \"address\"\nverifymessage \"address\" \"signature\" \"message\"\nversion\nwalletlock\nwalletpassphrase \"passphrase\" timeout\nwalletpassphrasechange \"oldpassphrase\" \"newpassphrase\"\ncreatenewaccount \"account\"\nexportwatchingwallet (\"account\" download=false)\ngetbestblock\ngetunconfirmedbalance (\"account\")\nlistaddresstransactions [\"address\",...] (\"account\")\nlistalltransactions (\"account\")\nrenameaccount \"oldaccount\" \"newaccount\"\nwalletislocked\nwalletinfo\npurchaseticket \"fromaccount\" spendlimit (minconf=1 \"ticketaddress\" numtickets \"pooladdress\" poolfees expiry \"comment\" ticketfee)\ngeneratevote \"blockhash\" height \"tickethash\" votebits \"votebitsext\"\ngetstakeinfo\ngetticketfee\nsetticketfee fee\ngetwalletfee\naddticket \"tickethex\"\nlistscripts\nstakepooluserinfo \"user\"\nticketsforaddress \"address\""

0 comments on commit 84751bc

Please sign in to comment.