forked from stellar/go
/
create_account.go
61 lines (53 loc) · 1.63 KB
/
create_account.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
package build
import (
"github.com/Kregopaulgue/go/amount"
"github.com/Kregopaulgue/go/support/errors"
"github.com/Kregopaulgue/go/xdr"
)
// CreateAccount groups the creation of a new CreateAccountBuilder with a call
// to Mutate.
func CreateAccount(muts ...interface{}) (result CreateAccountBuilder) {
result.Mutate(muts...)
return
}
// CreateAccountMutator is a interface that wraps the
// MutateCreateAccount operation. types may implement this interface to
// specify how they modify an xdr.PaymentOp object
type CreateAccountMutator interface {
MutateCreateAccount(*xdr.CreateAccountOp) error
}
// CreateAccountBuilder helps to build CreateAccountOp structs.
type CreateAccountBuilder struct {
O xdr.Operation
CA xdr.CreateAccountOp
Err error
}
// Mutate applies the provided mutators to this builder's payment or operation.
func (b *CreateAccountBuilder) Mutate(muts ...interface{}) {
for _, m := range muts {
var err error
switch mut := m.(type) {
case CreateAccountMutator:
err = mut.MutateCreateAccount(&b.CA)
case OperationMutator:
err = mut.MutateOperation(&b.O)
default:
err = errors.New("Mutator type not allowed")
}
if err != nil {
b.Err = err
return
}
}
}
// MutateCreateAccount for Destination sets the CreateAccountOp's Destination
// field
func (m Destination) MutateCreateAccount(o *xdr.CreateAccountOp) error {
return setAccountId(m.AddressOrSeed, &o.Destination)
}
// MutateCreateAccount for NativeAmount sets the CreateAccountOp's
// StartingBalance field
func (m NativeAmount) MutateCreateAccount(o *xdr.CreateAccountOp) (err error) {
o.StartingBalance, err = amount.Parse(m.Amount)
return
}