forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extend_footprint_ttl.go
59 lines (49 loc) · 1.37 KB
/
extend_footprint_ttl.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
package txnbuild
import (
"github.com/stellar/go/support/errors"
"github.com/stellar/go/xdr"
)
type ExtendFootprintTtl struct {
ExtendTo uint32
SourceAccount string
Ext xdr.TransactionExt
}
func (f *ExtendFootprintTtl) BuildXDR() (xdr.Operation, error) {
xdrOp := xdr.ExtendFootprintTtlOp{
Ext: xdr.ExtensionPoint{
V: 0,
},
ExtendTo: xdr.Uint32(f.ExtendTo),
}
body, err := xdr.NewOperationBody(xdr.OperationTypeExtendFootprintTtl, xdrOp)
if err != nil {
return xdr.Operation{}, errors.Wrap(err, "failed to build XDR Operation")
}
op := xdr.Operation{Body: body}
SetOpSourceAccount(&op, f.SourceAccount)
return op, nil
}
func (f *ExtendFootprintTtl) FromXDR(xdrOp xdr.Operation) error {
result, ok := xdrOp.Body.GetExtendFootprintTtlOp()
if !ok {
return errors.New("error parsing invoke host function operation from xdr")
}
f.SourceAccount = accountFromXDR(xdrOp.SourceAccount)
f.ExtendTo = uint32(result.ExtendTo)
return nil
}
func (f *ExtendFootprintTtl) Validate() error {
if f.SourceAccount != "" {
_, err := xdr.AddressToMuxedAccount(f.SourceAccount)
if err != nil {
return NewValidationError("SourceAccount", err.Error())
}
}
return nil
}
func (f *ExtendFootprintTtl) GetSourceAccount() string {
return f.SourceAccount
}
func (f *ExtendFootprintTtl) BuildTransactionExt() (xdr.TransactionExt, error) {
return f.Ext, nil
}