Skip to content

Commit

Permalink
Merge pull request #165 from tonkeeper/locker
Browse files Browse the repository at this point in the history
Describe locker interface and its methods in abi
  • Loading branch information
mr-tron authored Aug 2, 2023
2 parents 25b0ed8 + 18030b6 commit ff714c2
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 12 deletions.
124 changes: 124 additions & 0 deletions abi/get_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var KnownGetMethodsDecoder = map[string][]func(tlb.VmStack) (string, any, error)
"dnsresolve": {DecodeDnsresolve_RecordsResult},
"get_auction_info": {DecodeGetAuctionInfoResult},
"get_authority_address": {DecodeGetAuthorityAddressResult},
"get_bill_address": {DecodeGetBillAddressResult},
"get_bill_amount": {DecodeGetBillAmountResult},
"get_channel_state": {DecodeGetChannelStateResult},
"get_collection_data": {DecodeGetCollectionDataResult},
Expand All @@ -21,6 +22,8 @@ var KnownGetMethodsDecoder = map[string][]func(tlb.VmStack) (string, any, error)
"get_full_domain": {DecodeGetFullDomainResult},
"get_jetton_data": {DecodeGetJettonDataResult},
"get_last_fill_up_time": {DecodeGetLastFillUpTimeResult},
"get_locker_bill_data": {DecodeGetLockerBillDataResult},
"get_locker_data": {DecodeGetLockerDataResult},
"get_member": {DecodeGetMember_WhalesNominatorResult},
"get_members_raw": {DecodeGetMembersRaw_WhalesNominatorResult},
"get_next_proof_info": {DecodeGetNextProofInfoResult},
Expand Down Expand Up @@ -63,6 +66,7 @@ var KnownSimpleGetMethods = map[int][]func(ctx context.Context, executor Executo
69506: {GetTelemintTokenName},
71463: {GetTorrentHash},
72748: {GetSaleData},
73490: {GetLockerData},
78748: {GetPublicKey},
80697: {GetAuctionInfo},
81467: {GetSubwalletId},
Expand All @@ -89,6 +93,7 @@ var KnownSimpleGetMethods = map[int][]func(ctx context.Context, executor Executo
107653: {GetPluginList},
111161: {ListNominators},
115150: {GetParams},
118274: {GetLockerBillData},
119378: {GetDomain},
120146: {GetPoolStatus},
122058: {IsActive},
Expand All @@ -103,6 +108,7 @@ var ResultTypes = []interface{}{
&Dnsresolve_RecordsResult{},
&GetAuctionInfoResult{},
&GetAuthorityAddressResult{},
&GetBillAddressResult{},
&GetBillAmountResult{},
&GetChannelStateResult{},
&GetCollectionDataResult{},
Expand All @@ -111,6 +117,8 @@ var ResultTypes = []interface{}{
&GetFullDomainResult{},
&GetJettonDataResult{},
&GetLastFillUpTimeResult{},
&GetLockerBillDataResult{},
&GetLockerDataResult{},
&GetMember_WhalesNominatorResult{},
&GetMembersRaw_WhalesNominatorResult{},
&GetNextProofInfoResult{},
Expand Down Expand Up @@ -268,6 +276,48 @@ func DecodeGetAuthorityAddressResult(stack tlb.VmStack) (resultType string, resu
return "GetAuthorityAddressResult", result, err
}

type GetBillAddressResult struct {
BillAddress tlb.MsgAddress
}

func GetBillAddress(ctx context.Context, executor Executor, reqAccountID tongo.AccountID, userAddress tlb.MsgAddress) (string, any, error) {
stack := tlb.VmStack{}
var (
val tlb.VmStackValue
err error
)
val, err = tlb.TlbStructToVmCellSlice(userAddress)
if err != nil {
return "", nil, err
}
stack.Put(val)

// MethodID = 130076 for "get_bill_address" method
errCode, stack, err := executor.RunSmcMethodByID(ctx, reqAccountID, 130076, 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){DecodeGetBillAddressResult} {
s, r, err := f(stack)
if err == nil {
return s, r, nil
}
}
return "", nil, fmt.Errorf("can not decode outputs")
}

func DecodeGetBillAddressResult(stack tlb.VmStack) (resultType string, resultAny any, err error) {
if len(stack) != 1 || (stack[0].SumType != "VmStkSlice") {
return "", nil, fmt.Errorf("invalid stack format")
}
var result GetBillAddressResult
err = stack.Unmarshal(&result)
return "GetBillAddressResult", result, err
}

type GetBillAmountResult struct {
Amount int64
}
Expand Down Expand Up @@ -538,6 +588,80 @@ func DecodeGetLastFillUpTimeResult(stack tlb.VmStack) (resultType string, result
return "GetLastFillUpTimeResult", result, err
}

type GetLockerBillDataResult struct {
LockerAddress tlb.MsgAddress
TotalCoinsDeposit uint64
UserAddress tlb.MsgAddress
LastWithdrawTime uint32
}

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

// MethodID = 118274 for "get_locker_bill_data" method
errCode, stack, err := executor.RunSmcMethodByID(ctx, reqAccountID, 118274, 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){DecodeGetLockerBillDataResult} {
s, r, err := f(stack)
if err == nil {
return s, r, nil
}
}
return "", nil, fmt.Errorf("can not decode outputs")
}

func DecodeGetLockerBillDataResult(stack tlb.VmStack) (resultType string, resultAny any, err error) {
if len(stack) != 4 || (stack[0].SumType != "VmStkSlice") || (stack[1].SumType != "VmStkTinyInt" && stack[1].SumType != "VmStkInt") || (stack[2].SumType != "VmStkSlice") || (stack[3].SumType != "VmStkTinyInt" && stack[3].SumType != "VmStkInt") {
return "", nil, fmt.Errorf("invalid stack format")
}
var result GetLockerBillDataResult
err = stack.Unmarshal(&result)
return "GetLockerBillDataResult", result, err
}

type GetLockerDataResult struct {
TotalCoinsLocked uint64
TotalReward uint64
DepositsEndTime uint32
VestingStartTime uint32
VestingTotalDuration uint32
UnlockPeriod uint32
}

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

// MethodID = 73490 for "get_locker_data" method
errCode, stack, err := executor.RunSmcMethodByID(ctx, reqAccountID, 73490, 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){DecodeGetLockerDataResult} {
s, r, err := f(stack)
if err == nil {
return s, r, nil
}
}
return "", nil, fmt.Errorf("can not decode outputs")
}

func DecodeGetLockerDataResult(stack tlb.VmStack) (resultType string, resultAny any, err error) {
if len(stack) != 6 || (stack[0].SumType != "VmStkTinyInt" && stack[0].SumType != "VmStkInt") || (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 != "VmStkTinyInt" && stack[4].SumType != "VmStkInt") || (stack[5].SumType != "VmStkTinyInt" && stack[5].SumType != "VmStkInt") {
return "", nil, fmt.Errorf("invalid stack format")
}
var result GetLockerDataResult
err = stack.Unmarshal(&result)
return "GetLockerDataResult", result, err
}

type GetMember_WhalesNominatorResult struct {
MemberBalance int64
MemberPendingDeposit int64
Expand Down
10 changes: 5 additions & 5 deletions abi/messages.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package abi

// Code autogenerated. DO NOT EDIT.
// Code autogenerated. DO NOT EDIT.

import (
"fmt"
"github.com/tonkeeper/tongo/boc"
"github.com/tonkeeper/tongo/tlb"
"fmt"
"github.com/tonkeeper/tongo/boc"
"github.com/tonkeeper/tongo/tlb"
)

// MessageDecoder takes in a message body as a cell and tries to decode it based on the first 4 bytes.
Expand Down Expand Up @@ -949,3 +948,4 @@ var KnownMsgTypes = map[string]any{
StonfiPaymentRequestMsgOp: StonfiPaymentRequestMsgBody{},
ElectorRecoverStakeResponseMsgOp: ElectorRecoverStakeResponseMsgBody{},
}

20 changes: 16 additions & 4 deletions abi/ordering.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package abi

// Code autogenerated. DO NOT EDIT.
// Code autogenerated. DO NOT EDIT.

import (
"context"
"github.com/tonkeeper/tongo"
"context"
"github.com/tonkeeper/tongo"
)


type ContractInterface string

// more wallet-related contract interfaces are defined in wallet.go
const (
Auction ContractInterface = "auction"
Domain ContractInterface = "domain"
Locker ContractInterface = "locker"
LockerBill ContractInterface = "locker_bill"
NftEditable ContractInterface = "nft_editable"
NftSale ContractInterface = "nft_sale"
NftSaleGetgems ContractInterface = "nft_sale_getgems"
Expand Down Expand Up @@ -104,6 +106,16 @@ var methodInvocationOrder = []MethodDescription{
InvokeFn: GetLastFillUpTime,
ImplementedBy: []ContractInterface{Domain},
},
{
Name: "get_locker_bill_data",
InvokeFn: GetLockerBillData,
ImplementedBy: []ContractInterface{LockerBill},
},
{
Name: "get_locker_data",
InvokeFn: GetLockerData,
ImplementedBy: []ContractInterface{Locker},
},
{
Name: "get_members_raw",
InvokeFn: GetMembersRaw,
Expand Down
29 changes: 29 additions & 0 deletions abi/schemas/locker.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<abi>
<get_method name="get_locker_bill_data" interface="locker_bill">
<output fixed_length="true">
<slice name="locker_address">msgaddress</slice>
<int name="total_coins_deposit">uint64</int>
<slice name="user_address">msgaddress</slice>
<int name="last_withdraw_time">uint32</int>
</output>
</get_method>
<get_method name="get_locker_data" interface="locker">
<output fixed_length="true">
<int name="total_coins_locked">uint64</int>
<int name="total_reward">uint64</int>
<int name="deposits_end_time">uint32</int>
<int name="vesting_start_time">uint32</int>
<int name="vesting_total_duration">uint32</int>
<int name="unlock_period">uint32</int>
</output>
</get_method>
<get_method name="get_bill_address" interface="locker">
<input>
<slice name="user_address">msgaddress</slice>
</input>
<output fixed_length="true">
<slice name="bill_address">msgaddress</slice>
</output>
</get_method>

</abi>
6 changes: 3 additions & 3 deletions abi/types.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package abi

// Code autogenerated. DO NOT EDIT.
// Code autogenerated. DO NOT EDIT.

import (
"github.com/tonkeeper/tongo/tlb"
"github.com/tonkeeper/tongo/tlb"
)

type ClosingConfig struct {
Expand Down Expand Up @@ -712,3 +711,4 @@ type StonfiPaymentRequestMsgBody struct {
type ElectorRecoverStakeResponseMsgBody struct {
QueryId uint64
}

0 comments on commit ff714c2

Please sign in to comment.