-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtypes.go
More file actions
102 lines (86 loc) · 2.68 KB
/
types.go
File metadata and controls
102 lines (86 loc) · 2.68 KB
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
package operations
import (
"fmt"
"github.com/block-vision/sui-go-sdk/sui"
"github.com/smartcontractkit/chainlink-sui/bindings/bind"
rel "github.com/smartcontractkit/chainlink-sui/relayer/signer"
)
type OpTxInput[I any] struct {
Input I
NoExecute bool
}
type OpTxResult[O any] struct {
Digest string
PackageId string
Objects O
Call TransactionCall
}
type TransactionCall struct {
PackageID string
LatestPackageID string // optional: when set, the PTB MoveCall targets this (upgraded) package while PackageID remains the on-chain MCMS identity
Module string
Function string
Data []byte
StateObjID string
TypeArgs []string
}
type OpTxDeps struct {
Client sui.ISuiAPI
Signer rel.SuiSigner
// We could have some logic to modify the gas based on input
GetCallOpts func() *bind.CallOpts
SuiRPC string
}
func NewSuiOperationName(pkg string, module string, action string) string {
return fmt.Sprintf("sui-%s-%s-%s", pkg, module, action)
}
func ToTransactionCall(call *bind.EncodedCall, stateObjID string) (TransactionCall, error) {
if call == nil {
return TransactionCall{}, fmt.Errorf("nil call provided")
}
calldata, err := extractByteArgsFromEncodedCall(*call)
if err != nil {
return TransactionCall{}, fmt.Errorf("failed to extract byte args from encoded call: %w", err)
}
return TransactionCall{
PackageID: call.Module.PackageID,
Module: call.Module.ModuleName,
Function: call.Function,
Data: calldata,
TypeArgs: []string{},
StateObjID: stateObjID,
}, nil
}
func ToTransactionCallWithTypeArgs(call *bind.EncodedCall, stateObjID string, typeArgs []string) (TransactionCall, error) {
if call == nil {
return TransactionCall{}, fmt.Errorf("nil call provided")
}
calldata, err := extractByteArgsFromEncodedCall(*call)
if err != nil {
return TransactionCall{}, fmt.Errorf("failed to extract byte args from encoded call: %w", err)
}
return TransactionCall{
PackageID: call.Module.PackageID,
Module: call.Module.ModuleName,
Function: call.Function,
Data: calldata,
TypeArgs: typeArgs,
StateObjID: stateObjID,
}, nil
}
func extractByteArgsFromEncodedCall(encodedCall bind.EncodedCall) ([]byte, error) {
var args []byte
for _, callArg := range encodedCall.CallArgs {
if callArg.CallArg.UnresolvedObject != nil {
args = append(args, callArg.CallArg.UnresolvedObject.ObjectId[:]...)
}
if callArg.CallArg.Pure != nil {
args = append(args, callArg.CallArg.Pure.Bytes...)
}
// we don't support resolved objects
if callArg.CallArg.Object != nil {
return nil, fmt.Errorf("resolved objects are not supported in transaction call encoding")
}
}
return args, nil
}