Skip to content

Commit

Permalink
add multisig orders info
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-tron committed Jun 9, 2024
1 parent 970bb9f commit 7fc1502
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 2 deletions.
44 changes: 44 additions & 0 deletions abi/get_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var KnownGetMethodsDecoder = map[string][]func(tlb.VmStack) (string, any, error)
"get_nft_content": {DecodeGetNftContentResult},
"get_nft_data": {DecodeGetNftDataResult},
"get_nominator_data": {DecodeGetNominatorDataResult},
"get_order_data": {DecodeGetOrderDataResult},
"get_params": {DecodeGetParams_WhalesNominatorResult},
"get_plugin_list": {DecodeGetPluginListResult},
"get_pool_data": {DecodeGetPoolData_StonfiResult, DecodeGetPoolData_TfResult},
Expand Down Expand Up @@ -133,6 +134,7 @@ var KnownSimpleGetMethods = map[int][]func(ctx context.Context, executor Executo
120146: {GetPoolStatus},
122058: {IsActive},
122498: {GetTelemintAuctionState},
123832: {GetOrderData},
123928: {GetStakingStatus},
128085: {GetRouterData},
128979: {JettonWalletLockData},
Expand Down Expand Up @@ -175,6 +177,7 @@ var resultTypes = []interface{}{
&GetNftContentResult{},
&GetNftDataResult{},
&GetNominatorDataResult{},
&GetOrderDataResult{},
&GetParams_WhalesNominatorResult{},
&GetPluginListResult{},
&GetPoolData_StonfiResult{},
Expand Down Expand Up @@ -1449,6 +1452,47 @@ func DecodeGetNominatorDataResult(stack tlb.VmStack) (resultType string, resultA
return "GetNominatorDataResult", result, err
}

type GetOrderDataResult struct {
MultisigAddress tlb.MsgAddress
OrderSeqno tlb.Int256
Threshold uint8
SentForExecution bool
Signers tlb.Hashmap[tlb.Uint8, tlb.MsgAddress]
ApprovalsMask tlb.Int256
ApprovalsNum uint8
ExpirationDate uint64
Order MultisigOrder
}

func GetOrderData(ctx context.Context, executor Executor, reqAccountID ton.AccountID) (string, any, error) {
stack := tlb.VmStack{}

// MethodID = 123832 for "get_order_data" method
errCode, stack, err := executor.RunSmcMethodByID(ctx, reqAccountID, 123832, stack)
if err != nil {
return "", nil, err
}
if errCode != 0 && errCode != 1 {
return "", nil, fmt.Errorf("method execution failed with code: %v", errCode)
}
for _, f := range []func(tlb.VmStack) (string, any, error){DecodeGetOrderDataResult} {
s, r, err := f(stack)
if err == nil {
return s, r, nil
}
}
return "", nil, fmt.Errorf("can not decode outputs")
}

func DecodeGetOrderDataResult(stack tlb.VmStack) (resultType string, resultAny any, err error) {
if len(stack) < 9 || (stack[0].SumType != "VmStkSlice") || (stack[1].SumType != "VmStkTinyInt" && stack[1].SumType != "VmStkInt") || (stack[2].SumType != "VmStkTinyInt" && stack[2].SumType != "VmStkInt") || (stack[3].SumType != "VmStkTinyInt" && stack[3].SumType != "VmStkInt") || (stack[4].SumType != "VmStkCell") || (stack[5].SumType != "VmStkTinyInt" && stack[5].SumType != "VmStkInt") || (stack[6].SumType != "VmStkTinyInt" && stack[6].SumType != "VmStkInt") || (stack[7].SumType != "VmStkTinyInt" && stack[7].SumType != "VmStkInt") || (stack[8].SumType != "VmStkCell") {
return "", nil, fmt.Errorf("invalid stack format")
}
var result GetOrderDataResult
err = stack.Unmarshal(&result)
return "GetOrderDataResult", result, err
}

type GetParams_WhalesNominatorResult struct {
Enabled bool
UpdatesEnables bool
Expand Down
12 changes: 10 additions & 2 deletions abi/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,10 @@ var methodInvocationOrder = []MethodDescription{
Name: "get_nft_data",
InvokeFn: GetNftData,
},
{
Name: "get_order_data",
InvokeFn: GetOrderData,
},
{
Name: "get_params",
InvokeFn: GetParams,
Expand Down Expand Up @@ -890,7 +894,9 @@ var knownContracts = map[ton.Bits256]knownContractDescription{
},
ton.MustParseHash("a01e057fbd4288402b9898d78d67bd4e90254c93c5866879bc2d1d12865436bc"): {
contractInterfaces: []ContractInterface{MultisigOrderV2},
getMethods: []InvokeFn{},
getMethods: []InvokeFn{
GetOrderData,
},
},
ton.MustParseHash("a0cfc2c48aee16a271f2cfc0b7382d81756cecb1017d077faaab3bb602f6868c"): {
contractInterfaces: []ContractInterface{WalletV1R1},
Expand All @@ -916,7 +922,9 @@ var knownContracts = map[ton.Bits256]knownContractDescription{
},
ton.MustParseHash("d3d14da9a627f0ec3533341829762af92b9540b21bf03665fac09c2b46eabbac"): {
contractInterfaces: []ContractInterface{MultisigV2},
getMethods: []InvokeFn{},
getMethods: []InvokeFn{
GetMultisigData,
},
},
ton.MustParseHash("d4902fcc9fad74698fa8e353220a68da0dcf72e32bcb2eb9ee04217c17d3062c"): {
contractInterfaces: []ContractInterface{WalletV1R2},
Expand Down
8 changes: 8 additions & 0 deletions abi/parser/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ func (g *Generator) checkType(s string) (string, error) {
if typeName, prs := g.knownTypes[strings.ToLower(s)]; prs {
return typeName.Name, nil
}
if strings.HasPrefix(s, "Hashmap") {
t := strings.Split(s, " ")
subType, err := g.checkType(t[2])
if err != nil {
return "", err
}
return fmt.Sprintf("tlb.%v[tlb.Uint%s, %v]", t[0], t[1], subType), nil
}
_, ok := g.newTlbTypes[s]
if !ok {
return "", fmt.Errorf("not defined type: %s", s)
Expand Down
17 changes: 17 additions & 0 deletions abi/schemas/multisig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<interface name="multisig_v2">
<code_hash>d3d14da9a627f0ec3533341829762af92b9540b21bf03665fac09c2b46eabbac</code_hash>
<get_method name="get_multisig_data"/>
<error code="1007">Unauthorized proposer</error>
<error code="1008">Invalid new order</error>
<error code="100">Not enough ton</error>
Expand All @@ -29,6 +30,7 @@

<interface name="multisig_order_v2">
<code_hash>a01e057fbd4288402b9898d78d67bd4e90254c93c5866879bc2d1d12865436bc</code_hash> <!-- with library -->
<get_method name="get_order_data"/>
<error code="104">Unauthorized init</error>
<error code="105">Already inited</error>
<error code="106">Unauthorized sign</error>
Expand All @@ -48,6 +50,21 @@
</output>
</get_method>


<get_method name="get_order_data">
<output>
<slice name="multisig_address">msgaddress</slice>
<int name="order_seqno">int256</int>
<int name="threshold">uint8</int>
<int name="sent_for_execution">bool</int>
<cell name="signers">Hashmap 8 MsgAddress</cell>
<int name="approvals_mask">int256</int>
<int name="approvals_num">uint8</int>
<int name="expiration_date">uint64</int>
<cell name="order">MultisigOrder</cell>
</output>
</get_method>

<internal name="multisig_new_order">
new_order#f718510f query_id:uint64
order_seqno:uint256
Expand Down

0 comments on commit 7fc1502

Please sign in to comment.