Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR to see changes from base repository #1

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ _cgo_export.*
_testmain.go

*.exe
/.idea
31 changes: 31 additions & 0 deletions btcjson/walletsvrcmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,36 @@ type SendToAddressCmd struct {
CommentTo *string
}

// NewTransferTransactionCmd returns a new instance which can be used to issue a
// transfertransaction JSON-RPC command.
func NewTransferTransactionCmd(address string, txId string) *TransferTransactionCmd {
return &TransferTransactionCmd{
Address: address,
TxId: txId,
}
}

// TransferTransactionCmd defines the transfertransaction JSON-RPC command.
type TransferTransactionCmd struct {
Address string
TxId string
}

// TODO : Write summary
func NewSendPostDatedTxCmd(address string, amount int64, lockTime uint32) *SendPostDatedTxCmd {
return &SendPostDatedTxCmd{
Address: address,
Amount: amount,
LockTime: lockTime,
}
}

type SendPostDatedTxCmd struct {
Address string
Amount int64
LockTime uint32
}

// NewSendToAddressCmd returns a new instance which can be used to issue a
// sendtoaddress JSON-RPC command.
//
Expand Down Expand Up @@ -688,6 +718,7 @@ func init() {
MustRegisterCmd("move", (*MoveCmd)(nil), flags)
MustRegisterCmd("sendfrom", (*SendFromCmd)(nil), flags)
MustRegisterCmd("sendmany", (*SendManyCmd)(nil), flags)
MustRegisterCmd("transfertransaction", (*TransferTransactionCmd)(nil), flags)
MustRegisterCmd("sendtoaddress", (*SendToAddressCmd)(nil), flags)
MustRegisterCmd("setaccount", (*SetAccountCmd)(nil), flags)
MustRegisterCmd("settxfee", (*SetTxFeeCmd)(nil), flags)
Expand Down
14 changes: 14 additions & 0 deletions btcjson/walletsvrcmds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,20 @@ func TestWalletSvrCmds(t *testing.T) {
Comment: btcjson.String("comment"),
},
},
{
name: "transfertransaction",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("transfertransaction", "1Address", "0000-0000")
},
staticCmd: func() interface{} {
return btcjson.NewTransferTransactionCmd("1Address", "0000-0000")
},
marshalled: `{"jsonrpc":"1.0","method":"transfertransaction","params":["1Address","0000-0000"],"id":1}`,
unmarshalled: &btcjson.TransferTransactionCmd{
Address: "1Address",
TxId: "0000-0000",
},
},
{
name: "sendtoaddress",
newCmd: func() (interface{}, error) {
Expand Down
54 changes: 54 additions & 0 deletions rpcclient/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,60 @@ func (c *Client) SetTxFee(fee btcutil.Amount) error {
return c.SetTxFeeAsync(fee).Receive()
}

// TransferTransaction
//
// FutureTransferTransactionResult is a future promise to deliver the result of a
// TransferTransactionAsync RPC invocation (or an applicable error).
type FutureTransferTransactionResult chan *response

// Receive waits for the response promised by the future and returns the hash
// of the transaction transferring the transaction of the passed id to the given address.
func (r FutureTransferTransactionResult) Receive() (*chainhash.Hash, error) {
res, err := receiveFuture(r)
if err != nil {
return nil, err
}

// Unmarshal result as a string.
var txHash string
err = json.Unmarshal(res, &txHash)
if err != nil {
return nil, err
}

return chainhash.NewHashFromStr(txHash)
}

// TransferTransactionAsync returns an instance of a type that can be used to get the
// result of the RPC at some future time by invoking the Receive function on the
// returned instance.
//
// See TransferTransaction for the blocking version and more details.
func (c *Client) TransferTransactionAsync(address btcutil.Address, txId string) FutureTransferTransactionResult {
addr := address.EncodeAddress()
cmd := btcjson.NewTransferTransactionCmd(addr, txId)
return c.sendCmd(cmd)
}

// TransferTransaction transfers the transaction of the passed id to the given address.
//
// NOTE: This function requires to the wallet to be unlocked. See the
// WalletPassphrase function for more details.
func (c *Client) TransferTransaction(address btcutil.Address, txId string) (*chainhash.Hash, error) {
return c.TransferTransactionAsync(address, txId).Receive()
}

// TODO : Write summary
func (c *Client) SendPostDatedTransactionAsync(address btcutil.Address, amount int64, lockTime uint32) FutureTransferTransactionResult {
addr := address.EncodeAddress()
cmd := btcjson.NewSendPostDatedTxCmd(addr, amount, lockTime)
return c.sendCmd(cmd)
}

func (c *Client) SendPostDatedTransaction(address btcutil.Address, amount int64, lockTime uint32) (*chainhash.Hash, error) {
return c.SendPostDatedTransactionAsync(address, amount, lockTime).Receive()
}

// FutureSendToAddressResult is a future promise to deliver the result of a
// SendToAddressAsync RPC invocation (or an applicable error).
type FutureSendToAddressResult chan *response
Expand Down
3 changes: 2 additions & 1 deletion rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ var rpcAskWallet = map[string]struct{}{
"sendfrom": {},
"sendmany": {},
"sendtoaddress": {},
"transfertransaction": {},
"setaccount": {},
"settxfee": {},
"signmessage": {},
Expand Down Expand Up @@ -4281,7 +4282,7 @@ func newRPCServer(config *rpcserverConfig) (*rpcServer, error) {
gbtWorkState: newGbtWorkState(config.TimeSource),
helpCacher: newHelpCacher(),
requestProcessShutdown: make(chan struct{}),
quit: make(chan int),
quit: make(chan int),
}
if cfg.RPCUser != "" && cfg.RPCPass != "" {
login := cfg.RPCUser + ":" + cfg.RPCPass
Expand Down