tact中的map结构:
struct RoundInfo {
// Purchase records
quotient: map<Int as uint32, BuyInfo>; // key is sequence number
// Order anti-duplication records, key is order number, value is sequence number
orders: map<Int as uint32, Int as uint16>;
}
go调用的时候需要采用这种结构体进行对应:
type BatchSyncOrderMsg3 struct {
RoundId uint32
Quotient tlb.HashmapE[tlb.Uint32, tlb.Ref[BuyInfo]] // 订单序列号:购买信息
Orders tlb.HashmapE[tlb.Uint32, tlb.Uint16] // 订单号码: 订单序列号
}
调用方式:把go map转成tlb.HashmapE形式
func (t TonApiServiceImpl) BatchSyncOrder3(ctx context.Context, roundId uint32, orders map[uint32]uint16, quotient map[uint32]chainservice.BuyInfo, roundContractConfig *chainservice.RoundContractConfig) (string, error) {
if roundContractConfig == nil {
roundContractConfig = t.defaultRoundContractConfig
}
msg := BatchSyncOrderMsg3{
RoundId: roundId,
}
{
var keys []tlb.Uint32
var values []tlb.Uint16
for key, value := range orders {
keys = append(keys, tlb.Uint32(key))
values = append(values, tlb.Uint16(value))
}
msg.Orders = tlb.NewHashmapE(keys, values)
}
{
var keys []tlb.Uint32
var values []tlb.Ref[BuyInfo]
for key, value := range quotient {
keys = append(keys, tlb.Uint32(key))
tonAddress := tongo.MustParseAddress(value.Address)
values = append(values, tlb.Ref[BuyInfo]{
Value: BuyInfo{
StartLuckNum: value.StartLuckNum,
Amount: value.NifiNum,
Address: tonAddress.ID.ToMsgAddress(),
},
})
}
msg.Quotient = tlb.NewHashmapE(keys, values)
}
return t.InvokeContract(ctx, roundContractConfig.ContractAddress, BatchSyncOrderMethodId, msg, 51_000_000)
}
标签:map,keys,tact,value,tlb,values,ton,Uint32 From: https://www.cnblogs.com/zhanchenjin/p/18472064