@@ -9,27 +9,147 @@ import (
99 "github.com/keybase/go-keybase-chat-bot/kbchat/types/stellar1"
1010)
1111
12- type WalletOutput struct {
13- Result stellar1.PaymentCLILocal `json:"result"`
12+ type walletMethod string
13+
14+ type sendOptions struct {
15+ Recipient string `json:"recipient"`
16+ Amount string `json:"amount"`
17+ Currency * string `json:"currency"`
18+ Message * string `json:"message"`
19+ FromAccountID * string `json:"from-account-id"`
20+ MemoText * string `json:"memo-text"`
21+ }
22+
23+ type SendOutput struct {
24+ Result stellar1.SendResultCLILocal `json:"result"`
25+ }
26+
27+ type CancelOutput struct {
28+ Result stellar1.RelayClaimResult `json:"result"`
29+ }
30+
31+ type walletTxIDAPIReq struct {
32+ Method walletMethod `json:"method"`
33+ Params walletTxIDParams `json:"params"`
34+ }
35+
36+ type walletTxIDParams struct {
37+ Options txIDOptions `json:"options"`
38+ }
39+
40+ type txIDOptions struct {
41+ TxID string `json:"txid"`
42+ }
43+
44+ type walletSendAPIReq struct {
45+ Method walletMethod `json:"method"`
46+ Params walletSendParams `json:"params"`
47+ }
48+
49+ type walletSendParams struct {
50+ Options sendOptions `json:"options"`
51+ }
52+
53+ func (a * API ) GetWalletTxDetails (txID string ) (result stellar1.PaymentCLILocal , err error ) {
54+ a .Lock ()
55+ defer a .Unlock ()
56+
57+ type res struct {
58+ Result stellar1.PaymentCLILocal `json:"result"`
59+ }
60+
61+ opts := txIDOptions {
62+ TxID : txID ,
63+ }
64+ args := walletTxIDAPIReq {Method : "details" , Params : walletTxIDParams {Options : opts }}
65+ apiInput , err := json .Marshal (args )
66+ if err != nil {
67+ return result , err
68+ }
69+ cmd := a .runOpts .Command ("wallet" , "api" )
70+ cmd .Stdin = strings .NewReader (string (apiInput ))
71+ var out bytes.Buffer
72+ cmd .Stdout = & out
73+ err = cmd .Run ()
74+ if err != nil {
75+ return result , err
76+ }
77+
78+ response := res {}
79+ if err := json .Unmarshal (out .Bytes (), & response ); err != nil {
80+ return result , fmt .Errorf ("unable to decode wallet output: %s" , err .Error ())
81+ }
82+
83+ return response .Result , nil
1484}
1585
16- func (a * API ) GetWalletTxDetails ( txID string ) (wOut WalletOutput , err error ) {
86+ func (a * API ) SendWalletTx ( recipient string , amount string , currency * string , message * string , fromAccountID * string , memoText * string ) (result stellar1. SendResultCLILocal , err error ) {
1787 a .Lock ()
1888 defer a .Unlock ()
1989
20- apiInput := fmt .Sprintf (`{"method": "details", "params": {"options": {"txid": "%s"}}}` , txID )
90+ type res struct {
91+ Result stellar1.SendResultCLILocal `json:"result"`
92+ }
93+
94+ opts := sendOptions {
95+ Recipient : recipient ,
96+ Amount : amount ,
97+ Currency : currency ,
98+ Message : message ,
99+ FromAccountID : fromAccountID ,
100+ MemoText : memoText ,
101+ }
102+ args := walletSendAPIReq {Method : "send" , Params : walletSendParams {Options : opts }}
103+ apiInput , err := json .Marshal (args )
104+ if err != nil {
105+ return result , err
106+ }
107+ cmd := a .runOpts .Command ("wallet" , "api" )
108+ cmd .Stdin = strings .NewReader (string (apiInput ))
109+ var out bytes.Buffer
110+ cmd .Stdout = & out
111+ err = cmd .Run ()
112+ if err != nil {
113+ return result , err
114+ }
115+
116+ response := res {}
117+ if err := json .Unmarshal (out .Bytes (), & response ); err != nil {
118+ return result , fmt .Errorf ("unable to decode wallet output: %s" , err .Error ())
119+ }
120+
121+ return response .Result , nil
122+ }
123+
124+ func (a * API ) CancelWalletTx (txID string ) (result stellar1.RelayClaimResult , err error ) {
125+ a .Lock ()
126+ defer a .Unlock ()
127+
128+ type res struct {
129+ Result stellar1.RelayClaimResult `json:"result"`
130+ }
131+
132+ opts := txIDOptions {
133+ TxID : txID ,
134+ }
135+ args := walletTxIDAPIReq {Method : "cancel" , Params : walletTxIDParams {Options : opts }}
136+ apiInput , err := json .Marshal (args )
137+ if err != nil {
138+ return result , err
139+ }
21140 cmd := a .runOpts .Command ("wallet" , "api" )
22- cmd .Stdin = strings .NewReader (apiInput )
141+ cmd .Stdin = strings .NewReader (string ( apiInput ) )
23142 var out bytes.Buffer
24143 cmd .Stdout = & out
25144 err = cmd .Run ()
26145 if err != nil {
27- return wOut , err
146+ return result , err
28147 }
29148
30- if err := json .Unmarshal (out .Bytes (), & wOut ); err != nil {
31- return wOut , fmt .Errorf ("unable to decode wallet output: %s" , err .Error ())
149+ response := res {}
150+ if err := json .Unmarshal (out .Bytes (), & response ); err != nil {
151+ return result , fmt .Errorf ("unable to decode wallet output: %s" , err .Error ())
32152 }
33153
34- return wOut , nil
154+ return response . Result , nil
35155}
0 commit comments