Skip to content

Commit

Permalink
Overload building unsigned transactions to allow switching fee direction
Browse files Browse the repository at this point in the history
Update method documentation.

remove constructor, clean up comments

remove unused method

remove unnecessary function

rename internal method

move options to struct

* rename 1Addr test values to standard dcr prefix
* consolidate tx options into struct w/ sane defaults
* push tx options higher up callstack
* make build unsigned tx minus fee private in createtx

update docs
  • Loading branch information
Sef committed Jun 20, 2019
1 parent 8b5855e commit 0f1b716
Show file tree
Hide file tree
Showing 12 changed files with 499 additions and 121 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
github.com/decred/dcrwallet/spv/v2 v2.0.0
github.com/decred/dcrwallet/ticketbuyer/v3 v3.0.0
github.com/decred/dcrwallet/version v1.0.1
github.com/decred/dcrwallet/wallet v1.3.0 // indirect
github.com/decred/dcrwallet/wallet/v2 v2.1.0
github.com/decred/dcrwallet/walletseed v1.0.1
github.com/decred/slog v1.0.0
Expand Down
13 changes: 13 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ github.com/aead/siphash v0.0.0-20170329201724-e404fcfc8885 h1:bBmEG9/q1xH07CqeeF
github.com/aead/siphash v0.0.0-20170329201724-e404fcfc8885/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 h1:w1UutsfOrms1J05zt7ISrnJIXKzwaspym5BTKGx93EI=
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0=
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd h1:R/opQEbFEy9JGkIguV40SvRY1uliPX8ifOvi6ICsFCw=
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
github.com/btcsuite/goleveldb v1.0.0 h1:Tvd0BfvqX9o823q1j2UZ/epQo09eJh6dTcRp79ilIN4=
Expand Down Expand Up @@ -58,6 +60,7 @@ github.com/decred/dcrd/dcrec v0.0.0-20180721005914-d26200ec716b/go.mod h1:cRAH1S
github.com/decred/dcrd/dcrec v0.0.0-20180721031028-5369a485acf6/go.mod h1:cRAH1SNk8Mi9hKBc/DHbeiWz/fyO8KWZR3H7okrIuOA=
github.com/decred/dcrd/dcrec v0.0.0-20180801202239-0761de129164 h1:N5s3yVfjBNW6XNG3gLxYpvt0IUjUsp/FRfC75QpSI+E=
github.com/decred/dcrd/dcrec v0.0.0-20180801202239-0761de129164/go.mod h1:cRAH1SNk8Mi9hKBc/DHbeiWz/fyO8KWZR3H7okrIuOA=
github.com/decred/dcrd/dcrec v0.0.0-20181212181811-1a370d38d671/go.mod h1:cRAH1SNk8Mi9hKBc/DHbeiWz/fyO8KWZR3H7okrIuOA=
github.com/decred/dcrd/dcrec v0.0.0-20190130161649-59ed4247a1d5/go.mod h1:cRAH1SNk8Mi9hKBc/DHbeiWz/fyO8KWZR3H7okrIuOA=
github.com/decred/dcrd/dcrec v1.0.0 h1:W+z6Es+Rai3MXYVoPAxYr5U1DGis0Co33scJ6uH2J6o=
github.com/decred/dcrd/dcrec v1.0.0/go.mod h1:HIaqbEJQ+PDzQcORxnqen5/V1FR3B4VpIfmePklt8Q8=
Expand All @@ -77,6 +80,8 @@ github.com/decred/dcrd/dcrec/secp256k1 v1.0.1 h1:EFWVd1p0t0Y5tnsm/dJujgV0ORogRJ6
github.com/decred/dcrd/dcrec/secp256k1 v1.0.1/go.mod h1:lhu4eZFSfTJWUnR3CFRcpD+Vta0KUAqnhTsTksHXgy0=
github.com/decred/dcrd/dcrjson v1.0.0 h1:50DnA0XeV2JrQXoHh43TCKmH+kz2gHjZ1Mj/Pdk7Oz0=
github.com/decred/dcrd/dcrjson v1.0.0/go.mod h1:ozddIaeF+EAvZZvFuB3zpfxhyxBGfvbt22crQh+PYuI=
github.com/decred/dcrd/dcrjson v1.1.0 h1:pFpbay3cWACkgloFxWjHBwlXWG2+S2QCJJzNxL40hwg=
github.com/decred/dcrd/dcrjson v1.1.0/go.mod h1:ozddIaeF+EAvZZvFuB3zpfxhyxBGfvbt22crQh+PYuI=
github.com/decred/dcrd/dcrjson/v2 v2.0.0 h1:W0q4Alh36c5N318eUpfmU8kXoCNgImMLI87NIXni9Us=
github.com/decred/dcrd/dcrjson/v2 v2.0.0/go.mod h1:FYueNy8BREAFq04YNEwcTsmGFcNqY+ehUUO81w2igi4=
github.com/decred/dcrd/dcrutil v1.1.1 h1:zOkGiumN/JkobhAgpG/zfFgUoolGKVGYT5na1hbYUoE=
Expand All @@ -91,10 +96,14 @@ github.com/decred/dcrd/hdkeychain v1.1.1 h1:6+BwOmPfEyw/Krm+91RXysc76F1jqCta3m45
github.com/decred/dcrd/hdkeychain v1.1.1/go.mod h1:CLBVXLoO63fIiqkv38KR23zXGSgrfiAWOybOKTneLhA=
github.com/decred/dcrd/hdkeychain/v2 v2.0.0 h1:b6GklXT+LeDumc0bDqMHkss+p2Bu+mgiUDhjAX01LOc=
github.com/decred/dcrd/hdkeychain/v2 v2.0.0/go.mod h1:tG+VpXfloIkNGHGd6NeoTElHWA68Wf1aP87zegXDGEw=
github.com/decred/dcrd/mempool v1.1.1 h1:ysFIS3HzEIJ88B1Y4OfL6wjzBurlChbKkzq54hPglGo=
github.com/decred/dcrd/mempool v1.1.1/go.mod h1:u1I2KRv9UHhx2crlbZXYoLDabWyQ8VnnHDSG53UdhCA=
github.com/decred/dcrd/mempool/v2 v2.0.0 h1:QoQC5Lri311unqCr/PejBEwNERWMSWtnSa7bpBFZjbQ=
github.com/decred/dcrd/mempool/v2 v2.0.0/go.mod h1:/AH0mFOKCglSdEDubF3oRDbWUmDj26gwnrIlFsr+lbM=
github.com/decred/dcrd/mining v1.1.0 h1:9Wtla+i+pEjfYsNCfixsipmyyoB26DgL4LSXWAin/zw=
github.com/decred/dcrd/mining v1.1.0/go.mod h1:NQEtX604XgNwKcPFId1hVTTiBqmVQDlnqV1yNqGl4oU=
github.com/decred/dcrd/rpcclient v1.1.0 h1:nQZ1qOJaLYoOTM1oQ2dLaqocb5TWI7gNBK+BTY7UVXk=
github.com/decred/dcrd/rpcclient v1.1.0/go.mod h1:SCwBs4d+aqRV2ChnriIZ1y/LgNVHG/2ieEC1vIop82s=
github.com/decred/dcrd/rpcclient/v2 v2.0.0 h1:Zy9twdEaOGUdCj/89LAs/IrStm6FcabxzBve4UsA73A=
github.com/decred/dcrd/rpcclient/v2 v2.0.0/go.mod h1:9XjbRHBSNqN+DXz8I47gUZszvVjvugqLGK8TZQ4c/u0=
github.com/decred/dcrd/txscript v1.0.1 h1:IMgxZFCw3AyG4EbKwywE3SDNshOSHsoUK1Wk/5GqWJ0=
Expand All @@ -113,6 +122,8 @@ github.com/decred/dcrwallet/spv/v2 v2.0.0 h1:JrU7rf9sL8hZwP3yPSv8bKVEXC99Glhf10Y
github.com/decred/dcrwallet/spv/v2 v2.0.0/go.mod h1:2usXom73CRn2wjPJAEPtn+RiXLJPcIlb4aqgjn3+Dog=
github.com/decred/dcrwallet/ticketbuyer/v3 v3.0.0 h1:xayh/Rb4vpD26NtwN8mZpnsumsol1leoorgVnUM0xTw=
github.com/decred/dcrwallet/ticketbuyer/v3 v3.0.0/go.mod h1:gVrHqQSymQsOz4IkFv7Z8s+c3o7gyw2EBS5j+arrzlg=
github.com/decred/dcrwallet/wallet v1.3.0 h1:RQ4uHIfbDF0ppyeVDkTr7GapeABCddUUKOSexTN7X1M=
github.com/decred/dcrwallet/wallet v1.3.0/go.mod h1:ItOhnw3C4znuLQVWACSq8jCLy221v9X0Xo0b/j5WqgU=
github.com/decred/dcrwallet/wallet/v2 v2.0.0 h1:ppSLjwu3DHmRWdnRbN53fu9AFjY0MqK40jzbZQAouG8=
github.com/decred/dcrwallet/wallet/v2 v2.0.0/go.mod h1:uDSN0GRTH583eSnPyPiTXNcZ9DrQ2tBqdm/tjp5rjwY=
github.com/decred/slog v1.0.0 h1:Dl+W8O6/JH6n2xIFN2p3DNjCmjYwvrXsjlSJTQQ4MhE=
Expand All @@ -126,6 +137,7 @@ github.com/golang/protobuf v1.1.0 h1:0iH4Ffd/meGoXqF2lSAhZHt8X+cPgkfn/cb6Cce5Vpc
github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
Expand Down Expand Up @@ -153,6 +165,7 @@ github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa
go.etcd.io/bbolt v1.3.2 h1:Z/90sZLPOeCy2PwprqkFa25PdkusRzaj9P8zm/KNyvk=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
golang.org/x/crypto v0.0.0-20180718160520-a2144134853f/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190131182504-b8fe1690c613/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 h1:ng3VDlRp5/DHpSWl02R4rM9I+8M2rhmsuLwAMmkLQWE=
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down
11 changes: 6 additions & 5 deletions internal/rpchelp/helpdescs_en_US.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,12 @@ var helpDescsEnUS = map[string]string{
"sendtoaddress--synopsis": "Authors, signs, and sends a transaction that outputs some amount to a payment address.\n" +
"Unlike sendfrom, outputs are always chosen from the default account.\n" +
"A change output is automatically included to send extra output value back to the original account.",
"sendtoaddress-address": "Address to pay",
"sendtoaddress-amount": "Amount to send to the payment address valued in decred",
"sendtoaddress-comment": "Unused",
"sendtoaddress-commentto": "Unused",
"sendtoaddress--result0": "The transaction hash of the sent transaction",
"sendtoaddress-address": "Address to pay",
"sendtoaddress-amount": "Amount to send to the payment address valued in decred",
"sendtoaddress-comment": "Unused",
"sendtoaddress-commentto": "Unused",
"sendtoaddress-subtractfeefromamount": "Toggles whether the tx fee is subtracted from the payment rather than the change",
"sendtoaddress--result0": "The transaction hash of the sent transaction",

// SendToMultisigCmd help.
"sendtomultisig--synopsis": "Authors, signs, and sends a transaction that outputs some amount to a multisig address.\n" +
Expand Down
29 changes: 24 additions & 5 deletions rpc/jsonrpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -2237,12 +2237,13 @@ func makeOutputs(pairs map[string]dcrutil.Amount, chainParams *chaincfg.Params)
// sendPairs creates and sends payment transactions.
// It returns the transaction hash in string format upon success
// All errors are returned in dcrjson.RPCError format
func sendPairs(w *wallet.Wallet, amounts map[string]dcrutil.Amount, account uint32, minconf int32) (string, error) {
func sendPairs(w *wallet.Wallet, amounts map[string]dcrutil.Amount,
options *wallet.CreateTxOptions) (string, error) {
outputs, err := makeOutputs(amounts, w.ChainParams())
if err != nil {
return "", err
}
txSha, err := w.SendOutputs(outputs, account, minconf)
txSha, err := w.SendOutputsWithOptions(outputs, options)
if err != nil {
if errors.Is(errors.Locked, err) {
return "", errWalletUnlockNeeded
Expand Down Expand Up @@ -2593,7 +2594,13 @@ func (s *Server) sendFrom(ctx context.Context, icmd interface{}) (interface{}, e
cmd.ToAddress: amt,
}

return sendPairs(w, pairs, account, minConf)
opt := &wallet.CreateTxOptions{
RecipientPaysFee: dcrjson.Bool(false),
MinimumConfirmations: dcrjson.Int32(minConf),
Account: dcrjson.Uint32(account),
}

return sendPairs(w, pairs, opt)
}

// sendMany handles a sendmany RPC request by creating a new transaction
Expand Down Expand Up @@ -2635,7 +2642,13 @@ func (s *Server) sendMany(ctx context.Context, icmd interface{}) (interface{}, e
pairs[k] = amt
}

return sendPairs(w, pairs, account, minConf)
opt := &wallet.CreateTxOptions{
RecipientPaysFee: dcrjson.Bool(false),
MinimumConfirmations: dcrjson.Int32(minConf),
Account: dcrjson.Uint32(account),
}

return sendPairs(w, pairs, opt)
}

// sendToAddress handles a sendtoaddress RPC request by creating a new
Expand Down Expand Up @@ -2671,8 +2684,14 @@ func (s *Server) sendToAddress(ctx context.Context, icmd interface{}) (interface
cmd.Address: amt,
}

opt := &wallet.CreateTxOptions{
RecipientPaysFee: cmd.SubtractFeeFromAmount,
MinimumConfirmations: dcrjson.Int32(1),
Account: dcrjson.Uint32(udb.DefaultAccountNum),
}

// sendtoaddress always spends from the default account, this matches bitcoind
return sendPairs(w, pairs, udb.DefaultAccountNum, 1)
return sendPairs(w, pairs, opt)
}

// sendToMultiSig handles a sendtomultisig RPC request by creating a new
Expand Down

0 comments on commit 0f1b716

Please sign in to comment.