-
Notifications
You must be signed in to change notification settings - Fork 499
/
invoke_host_function.go
63 lines (50 loc) · 1.44 KB
/
invoke_host_function.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
package txnbuild
import (
"github.com/stellar/go/support/errors"
"github.com/stellar/go/xdr"
)
type InvokeHostFunction struct {
HostFunction xdr.HostFunction
Auth []xdr.SorobanAuthorizationEntry
SourceAccount string
Ext xdr.TransactionExt
}
func (f *InvokeHostFunction) BuildXDR() (xdr.Operation, error) {
opType := xdr.OperationTypeInvokeHostFunction
xdrOp := xdr.InvokeHostFunctionOp{
HostFunction: f.HostFunction,
Auth: f.Auth,
}
body, err := xdr.NewOperationBody(opType, 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 *InvokeHostFunction) FromXDR(xdrOp xdr.Operation) error {
result, ok := xdrOp.Body.GetInvokeHostFunctionOp()
if !ok {
return errors.New("error parsing invoke host function operation from xdr")
}
f.SourceAccount = accountFromXDR(xdrOp.SourceAccount)
f.HostFunction = result.HostFunction
f.Auth = result.Auth
return nil
}
func (f *InvokeHostFunction) Validate() error {
if f.SourceAccount != "" {
_, err := xdr.AddressToMuxedAccount(f.SourceAccount)
if err != nil {
return NewValidationError("SourceAccount", err.Error())
}
}
return nil
}
func (f *InvokeHostFunction) GetSourceAccount() string {
return f.SourceAccount
}
func (f *InvokeHostFunction) BuildTransactionExt() (xdr.TransactionExt, error) {
return f.Ext, nil
}