-
Notifications
You must be signed in to change notification settings - Fork 496
/
go_string.go
255 lines (236 loc) · 7.93 KB
/
go_string.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
package xdr
import (
"fmt"
"strconv"
"strings"
)
// GoString prints Uint32 as decimal instead of hexadecimal numbers.
func (u Uint32) GoString() string {
return strconv.FormatInt(int64(u), 10)
}
// GoString implements fmt.GoStringer.
func (e TransactionEnvelope) GoString() string {
var sb strings.Builder
sb.WriteString(fmt.Sprintf("xdr.TransactionEnvelope{Type: xdr.%s,", envelopeTypeMap[int32(e.Type)]))
switch e.Type {
case EnvelopeTypeEnvelopeTypeTxV0:
sb.WriteString(fmt.Sprintf("V0: &%#v", *e.V0))
case EnvelopeTypeEnvelopeTypeTx:
sb.WriteString(fmt.Sprintf("V1: &%#v", *e.V1))
case EnvelopeTypeEnvelopeTypeTxFeeBump:
sb.WriteString(fmt.Sprintf("FeeBump: &%#v", *e.FeeBump))
default:
panic("Unknown type")
}
sb.WriteString("}")
return sb.String()
}
// GoString implements fmt.GoStringer.
func (e FeeBumpTransactionInnerTx) GoString() string {
var sb strings.Builder
sb.WriteString(fmt.Sprintf("xdr.FeeBumpTransactionInnerTx{Type: xdr.%s,", envelopeTypeMap[int32(e.Type)]))
switch e.Type {
case EnvelopeTypeEnvelopeTypeTx:
sb.WriteString(fmt.Sprintf("V1: &%#v", *e.V1))
default:
panic("Unknown type")
}
sb.WriteString("}")
return sb.String()
}
// GoString implements fmt.GoStringer.
func (a AccountId) GoString() string {
return fmt.Sprintf("xdr.MustAddress(%#v)", a.Address())
}
// GoString implements fmt.GoStringer.
func (a Asset) GoString() string {
if a.Type == AssetTypeAssetTypeNative {
return "xdr.MustNewNativeAsset()"
}
var typ, code, issuer string
a.MustExtract(&typ, &code, &issuer)
return fmt.Sprintf("xdr.MustNewCreditAsset(%#v, %#v)", code, issuer)
}
// GoString implements fmt.GoStringer.
func (m Memo) GoString() string {
switch m.Type {
case MemoTypeMemoNone:
return fmt.Sprintf("xdr.Memo{Type: xdr.%s}", memoTypeMap[int32(m.Type)])
case MemoTypeMemoText:
return fmt.Sprintf(`xdr.MemoText(%#v)`, *m.Text)
case MemoTypeMemoId:
return fmt.Sprintf(`xdr.MemoID(%d)`, *m.Id)
case MemoTypeMemoHash:
return fmt.Sprintf(`xdr.MemoHash(%#v)`, *m.Hash)
case MemoTypeMemoReturn:
return fmt.Sprintf(`xdr.MemoRetHash(%#v)`, *m.RetHash)
default:
panic("Unknown type")
}
}
// GoString implements fmt.GoStringer.
func (m MuxedAccount) GoString() string {
switch m.Type {
case CryptoKeyTypeKeyTypeEd25519:
accountID := m.ToAccountId()
return fmt.Sprintf("xdr.MustMuxedAddress(%#v)", accountID.Address())
case CryptoKeyTypeKeyTypeMuxedEd25519:
var sb strings.Builder
sb.WriteString("xdr.MuxedAccount{Type: xdr.CryptoKeyTypeKeyTypeMuxedEd25519,")
sb.WriteString(fmt.Sprintf("Med25519: &%#v", *m.Med25519))
sb.WriteString("}")
return sb.String()
default:
panic("Unknown type")
}
}
// GoString implements fmt.GoStringer.
func (o Operation) GoString() string {
var sb strings.Builder
sb.WriteString("xdr.Operation{")
if o.SourceAccount != nil {
if o.SourceAccount.Type == CryptoKeyTypeKeyTypeEd25519 {
accountID := o.SourceAccount.ToAccountId()
sb.WriteString(fmt.Sprintf("SourceAccount: xdr.MustMuxedAddressPtr(%#v),", accountID.Address()))
} else {
sb.WriteString(fmt.Sprintf("SourceAccount: &%#v,", *o.SourceAccount))
}
}
sb.WriteString(fmt.Sprintf("Body: %#v", o.Body))
sb.WriteString("}")
return sb.String()
}
// GoString implements fmt.GoStringer.
func (o OperationBody) GoString() string {
var sb strings.Builder
sb.WriteString(fmt.Sprintf("xdr.OperationBody{Type: xdr.%s,", operationTypeMap[int32(o.Type)]))
switch {
case o.CreateAccountOp != nil:
sb.WriteString(fmt.Sprintf("CreateAccountOp: &%#v", *o.CreateAccountOp))
case o.PaymentOp != nil:
sb.WriteString(fmt.Sprintf("PaymentOp: &%#v", *o.PaymentOp))
case o.PathPaymentStrictReceiveOp != nil:
sb.WriteString(fmt.Sprintf("PathPaymentStrictReceiveOp: &%#v", *o.PathPaymentStrictReceiveOp))
case o.ManageSellOfferOp != nil:
sb.WriteString(fmt.Sprintf("ManageSellOfferOp: &%#v", *o.ManageSellOfferOp))
case o.CreatePassiveSellOfferOp != nil:
sb.WriteString(fmt.Sprintf("CreatePassiveSellOfferOp: &%#v", *o.CreatePassiveSellOfferOp))
case o.SetOptionsOp != nil:
sb.WriteString(fmt.Sprintf("SetOptionsOp: &%#v", *o.SetOptionsOp))
case o.ChangeTrustOp != nil:
sb.WriteString(fmt.Sprintf("ChangeTrustOp: &%#v", *o.ChangeTrustOp))
case o.AllowTrustOp != nil:
sb.WriteString(fmt.Sprintf("AllowTrustOp: &%#v", *o.AllowTrustOp))
case o.Destination != nil:
sb.WriteString(fmt.Sprintf("Destination: %#v", *o.Destination))
case o.ManageDataOp != nil:
sb.WriteString(fmt.Sprintf("ManageDataOp: &%#v", *o.ManageDataOp))
case o.BumpSequenceOp != nil:
sb.WriteString(fmt.Sprintf("BumpSequenceOp: &%#v", *o.BumpSequenceOp))
case o.ManageBuyOfferOp != nil:
sb.WriteString(fmt.Sprintf("ManageBuyOfferOp: &%#v", *o.ManageBuyOfferOp))
case o.PathPaymentStrictSendOp != nil:
sb.WriteString(fmt.Sprintf("PathPaymentStrictSendOp: &%#v", *o.PathPaymentStrictSendOp))
default:
panic("Unknown type")
}
sb.WriteString("}")
return sb.String()
}
// GoString implements fmt.GoStringer.
func (s SetOptionsOp) GoString() string {
var sb strings.Builder
sb.WriteString("xdr.SetOptionsOp{")
if s.InflationDest != nil {
sb.WriteString(fmt.Sprintf("InflationDest: xdr.MustAddressPtr(%#v),", s.InflationDest.Address()))
}
if s.ClearFlags != nil {
sb.WriteString(fmt.Sprintf("ClearFlags: xdr.Uint32Ptr(%#v),", s.ClearFlags))
}
if s.SetFlags != nil {
sb.WriteString(fmt.Sprintf("SetFlags: xdr.Uint32Ptr(%#v),", s.SetFlags))
}
if s.MasterWeight != nil {
sb.WriteString(fmt.Sprintf("MasterWeight: xdr.Uint32Ptr(%#v),", s.MasterWeight))
}
if s.LowThreshold != nil {
sb.WriteString(fmt.Sprintf("LowThreshold: xdr.Uint32Ptr(%#v),", s.LowThreshold))
}
if s.MedThreshold != nil {
sb.WriteString(fmt.Sprintf("MedThreshold: xdr.Uint32Ptr(%#v),", s.MedThreshold))
}
if s.HighThreshold != nil {
sb.WriteString(fmt.Sprintf("HighThreshold: xdr.Uint32Ptr(%#v),", s.HighThreshold))
}
if s.HomeDomain != nil {
sb.WriteString(fmt.Sprintf("HomeDomain: xdr.String32Ptr(%#v),", *s.HomeDomain))
}
if s.Signer != nil {
sb.WriteString(fmt.Sprintf("Signer: &%#v,", *s.Signer))
}
sb.WriteString("}")
return sb.String()
}
// GoString implements fmt.GoStringer.
func (s ManageDataOp) GoString() string {
var sb strings.Builder
sb.WriteString("xdr.ManageDataOp{")
sb.WriteString(fmt.Sprintf("DataName: %#v,", s.DataName))
if s.DataValue == nil {
sb.WriteString("DataValue: nil")
} else {
sb.WriteString(fmt.Sprintf("DataValue: &%#v", *s.DataValue))
}
sb.WriteString("}")
return sb.String()
}
// GoString implements fmt.GoStringer.
func (s AssetCode) GoString() string {
var code string
switch s.Type {
case AssetTypeAssetTypeCreditAlphanum4:
code = string(s.AssetCode4[:])
case AssetTypeAssetTypeCreditAlphanum12:
code = string(s.AssetCode12[:])
default:
panic("Unknown type")
}
return fmt.Sprintf("xdr.MustNewAssetCodeFromString(%#v)", strings.TrimRight(code, string([]byte{0})))
}
// GoString implements fmt.GoStringer.
func (s Signer) GoString() string {
var sb strings.Builder
sb.WriteString("xdr.Signer{")
sb.WriteString(fmt.Sprintf("Key: xdr.MustSigner(%#v),", s.Key.Address()))
sb.WriteString(fmt.Sprintf("Weight: %#v", s.Weight))
sb.WriteString("}")
return sb.String()
}
// GoString implements fmt.GoStringer.
func (t *TimeBounds) GoString() string {
if t == nil {
return "nil"
}
return fmt.Sprintf("&xdr.TimeBounds{MinTime: xdr.TimePoint(%d), MaxTime: xdr.TimePoint(%d)}", t.MinTime, t.MaxTime)
}
// GoString implements fmt.GoStringer.
func (pt PreconditionType) GoString() string {
return "xdr." + preconditionTypeMap[int32(pt)]
}
// GoString implements fmt.GoStringer.
func (p Preconditions) GoString() string {
var sb strings.Builder
sb.WriteString(fmt.Sprintf("xdr.Preconditions{Type: %s, ", p.Type.GoString()))
switch p.Type {
case PreconditionTypePrecondNone:
sb.WriteString("nil")
case PreconditionTypePrecondTime:
sb.WriteString(fmt.Sprintf("TimeBounds: %s", p.TimeBounds.GoString()))
case PreconditionTypePrecondV2:
sb.WriteString(fmt.Sprintf("V2: {%#v}", p.V2))
default:
sb.WriteString("(unknown)")
}
sb.WriteString("}")
return sb.String()
}