From 69cfd7f798754c073e0321f25bd3b0297aa69e2b Mon Sep 17 00:00:00 2001 From: Niko Storni Date: Wed, 21 Sep 2022 22:53:02 +0200 Subject: [PATCH] add account_send adjust transaction summary fields --- extras/jsonrpc/daemon.go | 15 +++++++++++++++ extras/jsonrpc/daemon_test.go | 31 +++++++++++++++++++++++++++++-- extras/jsonrpc/daemon_types.go | 1 + 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/extras/jsonrpc/daemon.go b/extras/jsonrpc/daemon.go index 314817a..b8216c2 100644 --- a/extras/jsonrpc/daemon.go +++ b/extras/jsonrpc/daemon.go @@ -164,6 +164,21 @@ func (d *Client) SetRPCTimeout(timeout time.Duration) { // NEW SDK //============================================ +func (d *Client) AccountSend(accountID *string, amount, toAddress string) (*TransactionSummary, error) { + response := new(TransactionSummary) + args := struct { + AccountID *string `json:"account_id"` + Amount string `json:"amount"` + Addresses string `json:"addresses"` + }{ + AccountID: accountID, + Amount: amount, + Addresses: toAddress, + } + structs.DefaultTagName = "json" + return response, d.call(response, "account_send", structs.Map(args)) +} + func (d *Client) AccountList(page uint64, pageSize uint64) (*AccountListResponse, error) { response := new(AccountListResponse) return response, d.call(response, "account_list", map[string]interface{}{ diff --git a/extras/jsonrpc/daemon_test.go b/extras/jsonrpc/daemon_test.go index 1386ef9..fcff5b5 100644 --- a/extras/jsonrpc/daemon_test.go +++ b/extras/jsonrpc/daemon_test.go @@ -11,6 +11,7 @@ import ( "time" "github.com/shopspring/decimal" + "github.com/stretchr/testify/assert" "github.com/lbryio/lbry.go/v2/extras/errors" @@ -54,6 +55,32 @@ func TestClient_AccountFund(t *testing.T) { prettyPrint(*got) } +func TestClient_AccountSend(t *testing.T) { + d := NewClient("") + accounts, err := d.AccountList(1, 20) + if !assert.NoError(t, err) { + return + } + if !assert.NotEmpty(t, accounts.Items[1].ID) { + return + } + account := (accounts.Items)[1].ID + + addressess, err := d.AddressList(&account, nil, 1, 20) + if !assert.NoError(t, err) { + return + } + if !assert.NotEmpty(t, addressess.Items) { + return + } + + got, err := d.AccountSend(&account, "0.01", string(addressess.Items[0].Address)) + if !assert.NoError(t, err) { + return + } + prettyPrint(*got) +} + func TestClient_AccountList(t *testing.T) { d := NewClient("") got, err := d.AccountList(1, 20) @@ -130,11 +157,11 @@ func TestClient_ChannelCreate(t *testing.T) { State: util.PtrToString("Ticino"), City: util.PtrToString("Lugano"), }}, - ThumbnailURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"), + ThumbnailURL: util.PtrToString("https://scrn.storni.info/2022-06-10_17-18-29-409175881.png"), }, Email: util.PtrToString("niko@lbry.com"), WebsiteURL: util.PtrToString("https://lbry.com"), - CoverURL: util.PtrToString("https://scrn.storni.info/2019-04-12_15-43-25-001592625.png"), + CoverURL: util.PtrToString("https://scrn.storni.info/2022-06-10_17-18-29-409175881.png"), }) if err != nil { t.Error(err) diff --git a/extras/jsonrpc/daemon_types.go b/extras/jsonrpc/daemon_types.go index 6393431..f276874 100644 --- a/extras/jsonrpc/daemon_types.go +++ b/extras/jsonrpc/daemon_types.go @@ -264,6 +264,7 @@ type TransactionSummary struct { Inputs []Transaction `json:"inputs"` Outputs []Transaction `json:"outputs"` TotalFee string `json:"total_fee"` + TotalInput string `json:"total_input"` TotalOutput string `json:"total_output"` Txid string `json:"txid"` }