forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bump_footprint_expiration.go
59 lines (49 loc) · 1.44 KB
/
bump_footprint_expiration.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 BumpFootprintExpiration struct {
LedgersToExpire uint32
SourceAccount string
Ext xdr.TransactionExt
}
func (f *BumpFootprintExpiration) BuildXDR() (xdr.Operation, error) {
xdrOp := xdr.BumpFootprintExpirationOp{
Ext: xdr.ExtensionPoint{
V: 0,
},
LedgersToExpire: xdr.Uint32(f.LedgersToExpire),
}
body, err := xdr.NewOperationBody(xdr.OperationTypeBumpFootprintExpiration, 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 *BumpFootprintExpiration) FromXDR(xdrOp xdr.Operation) error {
result, ok := xdrOp.Body.GetBumpFootprintExpirationOp()
if !ok {
return errors.New("error parsing invoke host function operation from xdr")
}
f.SourceAccount = accountFromXDR(xdrOp.SourceAccount)
f.LedgersToExpire = uint32(result.LedgersToExpire)
return nil
}
func (f *BumpFootprintExpiration) Validate() error {
if f.SourceAccount != "" {
_, err := xdr.AddressToMuxedAccount(f.SourceAccount)
if err != nil {
return NewValidationError("SourceAccount", err.Error())
}
}
return nil
}
func (f *BumpFootprintExpiration) GetSourceAccount() string {
return f.SourceAccount
}
func (f *BumpFootprintExpiration) BuildTransactionExt() (xdr.TransactionExt, error) {
return f.Ext, nil
}