Skip to content

Commit 9e70632

Browse files
committed
clean up
1 parent 457eda0 commit 9e70632

2 files changed

Lines changed: 36 additions & 118 deletions

File tree

examples/send_cancel/send_cancel.go

Lines changed: 0 additions & 83 deletions
This file was deleted.

kbchat/wallet.go

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,6 @@ import (
1111

1212
type walletMethod string
1313

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-
3114
type walletTxIDAPIReq struct {
3215
Method walletMethod `json:"method"`
3316
Params walletTxIDParams `json:"params"`
@@ -50,14 +33,34 @@ type walletSendParams struct {
5033
Options sendOptions `json:"options"`
5134
}
5235

36+
type sendOptions struct {
37+
Recipient string `json:"recipient"`
38+
Amount string `json:"amount"`
39+
Currency *string `json:"currency"`
40+
Message *string `json:"message"`
41+
FromAccountID *string `json:"from-account-id"`
42+
MemoText *string `json:"memo-text"`
43+
}
44+
45+
type getRes struct {
46+
Result stellar1.PaymentCLILocal `json:"result"`
47+
Error Error `json:"error,omitempty"`
48+
}
49+
50+
type sendRes struct {
51+
Result stellar1.SendResultCLILocal `json:"result"`
52+
Error Error `json:"error,omitempty"`
53+
}
54+
55+
type cancelRes struct {
56+
Result stellar1.RelayClaimResult `json:"result"`
57+
Error Error `json:"error,omitempty"`
58+
}
59+
5360
func (a *API) GetWalletTxDetails(txID string) (result stellar1.PaymentCLILocal, err error) {
5461
a.Lock()
5562
defer a.Unlock()
5663

57-
type res struct {
58-
Result stellar1.PaymentCLILocal `json:"result"`
59-
}
60-
6164
opts := txIDOptions{
6265
TxID: txID,
6366
}
@@ -75,22 +78,20 @@ func (a *API) GetWalletTxDetails(txID string) (result stellar1.PaymentCLILocal,
7578
return result, err
7679
}
7780

78-
response := res{}
81+
response := getRes{}
7982
if err := json.Unmarshal(out.Bytes(), &response); err != nil {
8083
return result, fmt.Errorf("unable to decode wallet output: %s", err.Error())
8184
}
82-
85+
if response.Error.Message != "" {
86+
return result, response.Error
87+
}
8388
return response.Result, nil
8489
}
8590

8691
func (a *API) SendWalletTx(recipient string, amount string, currency *string, message *string, fromAccountID *string, memoText *string) (result stellar1.SendResultCLILocal, err error) {
8792
a.Lock()
8893
defer a.Unlock()
8994

90-
type res struct {
91-
Result stellar1.SendResultCLILocal `json:"result"`
92-
}
93-
9495
opts := sendOptions{
9596
Recipient: recipient,
9697
Amount: amount,
@@ -113,22 +114,20 @@ func (a *API) SendWalletTx(recipient string, amount string, currency *string, me
113114
return result, err
114115
}
115116

116-
response := res{}
117+
response := sendRes{}
117118
if err := json.Unmarshal(out.Bytes(), &response); err != nil {
118119
return result, fmt.Errorf("unable to decode wallet output: %s", err.Error())
119120
}
120-
121+
if response.Error.Message != "" {
122+
return result, response.Error
123+
}
121124
return response.Result, nil
122125
}
123126

124127
func (a *API) CancelWalletTx(txID string) (result stellar1.RelayClaimResult, err error) {
125128
a.Lock()
126129
defer a.Unlock()
127130

128-
type res struct {
129-
Result stellar1.RelayClaimResult `json:"result"`
130-
}
131-
132131
opts := txIDOptions{
133132
TxID: txID,
134133
}
@@ -147,10 +146,12 @@ func (a *API) CancelWalletTx(txID string) (result stellar1.RelayClaimResult, err
147146
return result, err
148147
}
149148

150-
response := res{}
149+
response := cancelRes{}
151150
if err := json.Unmarshal(out.Bytes(), &response); err != nil {
152151
return result, fmt.Errorf("unable to decode wallet output: %s", err.Error())
153152
}
154-
153+
if response.Error.Message != "" {
154+
return result, response.Error
155+
}
155156
return response.Result, nil
156157
}

0 commit comments

Comments
 (0)