forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
restore_footprint.go
56 lines (46 loc) · 1.25 KB
/
restore_footprint.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
package txnbuild
import (
"github.com/stellar/go/support/errors"
"github.com/stellar/go/xdr"
)
type RestoreFootprint struct {
SourceAccount string
Ext xdr.TransactionExt
}
func (f *RestoreFootprint) BuildXDR() (xdr.Operation, error) {
xdrOp := xdr.RestoreFootprintOp{
Ext: xdr.ExtensionPoint{
V: 0,
},
}
body, err := xdr.NewOperationBody(xdr.OperationTypeRestoreFootprint, 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 *RestoreFootprint) FromXDR(xdrOp xdr.Operation) error {
_, ok := xdrOp.Body.GetRestoreFootprintOp()
if !ok {
return errors.New("error parsing invoke host function operation from xdr")
}
f.SourceAccount = accountFromXDR(xdrOp.SourceAccount)
return nil
}
func (f *RestoreFootprint) Validate() error {
if f.SourceAccount != "" {
_, err := xdr.AddressToMuxedAccount(f.SourceAccount)
if err != nil {
return NewValidationError("SourceAccount", err.Error())
}
}
return nil
}
func (f *RestoreFootprint) GetSourceAccount() string {
return f.SourceAccount
}
func (f *RestoreFootprint) BuildTransactionExt() (xdr.TransactionExt, error) {
return f.Ext, nil
}