forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
operation.go
103 lines (95 loc) · 3.12 KB
/
operation.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package txnbuild
import (
"fmt"
"github.com/stellar/go/xdr"
)
// Operation represents the operation types of the Stellar network.
type Operation interface {
BuildXDR() (xdr.Operation, error)
FromXDR(xdrOp xdr.Operation) error
Validate() error
GetSourceAccount() string
}
// SetOpSourceAccount sets the source account ID on an Operation, allowing M-strkeys (as defined in SEP23).
func SetOpSourceAccount(op *xdr.Operation, sourceAccount string) {
if sourceAccount == "" {
return
}
var opSourceAccountID xdr.MuxedAccount
opSourceAccountID.SetAddress(sourceAccount)
op.SourceAccount = &opSourceAccountID
}
// operationFromXDR returns a txnbuild Operation from its corresponding XDR operation
func operationFromXDR(xdrOp xdr.Operation) (Operation, error) {
var newOp Operation
switch xdrOp.Body.Type {
case xdr.OperationTypeCreateAccount:
newOp = &CreateAccount{}
case xdr.OperationTypePayment:
newOp = &Payment{}
case xdr.OperationTypePathPaymentStrictReceive:
newOp = &PathPayment{}
case xdr.OperationTypeManageSellOffer:
newOp = &ManageSellOffer{}
case xdr.OperationTypeCreatePassiveSellOffer:
newOp = &CreatePassiveSellOffer{}
case xdr.OperationTypeSetOptions:
newOp = &SetOptions{}
case xdr.OperationTypeChangeTrust:
newOp = &ChangeTrust{}
case xdr.OperationTypeAllowTrust:
newOp = &AllowTrust{}
case xdr.OperationTypeAccountMerge:
newOp = &AccountMerge{}
case xdr.OperationTypeInflation:
newOp = &Inflation{}
case xdr.OperationTypeManageData:
newOp = &ManageData{}
case xdr.OperationTypeBumpSequence:
newOp = &BumpSequence{}
case xdr.OperationTypeManageBuyOffer:
newOp = &ManageBuyOffer{}
case xdr.OperationTypePathPaymentStrictSend:
newOp = &PathPaymentStrictSend{}
case xdr.OperationTypeBeginSponsoringFutureReserves:
newOp = &BeginSponsoringFutureReserves{}
case xdr.OperationTypeEndSponsoringFutureReserves:
newOp = &EndSponsoringFutureReserves{}
case xdr.OperationTypeCreateClaimableBalance:
newOp = &CreateClaimableBalance{}
case xdr.OperationTypeClaimClaimableBalance:
newOp = &ClaimClaimableBalance{}
case xdr.OperationTypeRevokeSponsorship:
newOp = &RevokeSponsorship{}
case xdr.OperationTypeClawback:
newOp = &Clawback{}
case xdr.OperationTypeClawbackClaimableBalance:
newOp = &ClawbackClaimableBalance{}
case xdr.OperationTypeSetTrustLineFlags:
newOp = &SetTrustLineFlags{}
case xdr.OperationTypeLiquidityPoolDeposit:
newOp = &LiquidityPoolDeposit{}
case xdr.OperationTypeLiquidityPoolWithdraw:
newOp = &LiquidityPoolWithdraw{}
case xdr.OperationTypeInvokeHostFunction:
newOp = &InvokeHostFunction{}
case xdr.OperationTypeBumpFootprintExpiration:
newOp = &BumpFootprintExpiration{}
case xdr.OperationTypeRestoreFootprint:
newOp = &RestoreFootprint{}
default:
return nil, fmt.Errorf("unknown operation type: %d", xdrOp.Body.Type)
}
err := newOp.FromXDR(xdrOp)
return newOp, err
}
func accountFromXDR(account *xdr.MuxedAccount) string {
if account != nil {
return account.Address()
}
return ""
}
// SorobanOperation represents a smart contract operation on the Stellar network.
type SorobanOperation interface {
BuildTransactionExt() (xdr.TransactionExt, error)
}