receive(msg: BatchSyncOrderMsg) {
self.requireOwner(); // Ensure the caller is the contract owner
let roundInfo: RoundInfo = self.rounds.get(msg.round)!!; // Fetch the information for the specified round
require(!(roundInfo.finish), "current round is finish");
let totalNifiNum: Int = 0;
if msg.order1.nifiNum > 0 {
require(roundInfo.orders.get(msg.order1.orderNumber) == null, "Duplicate order ID");
roundInfo.orders.set(msg.order1.orderNumber, BuyInfo{startLuckyNum: msg.order1.startLuckyNum, nifiNum: msg.order1.nifiNum});
totalNifiNum += msg.order1.nifiNum;
roundInfo.sequence += 1;
}
if msg.order2.nifiNum > 0 {
require(roundInfo.orders.get(msg.order2.orderNumber) == null, "Duplicate order ID");
roundInfo.orders.set(msg.order2.orderNumber, BuyInfo{startLuckyNum: msg.order2.startLuckyNum, nifiNum: msg.order2.nifiNum});
totalNifiNum += msg.order2.nifiNum;
roundInfo.sequence += 1;
}
针对这种代码如果orderNumber已经存在的话会报错,但是事实是同一个请求中重复的话是不报错的,我的理解是数据还没有生效(因为存储数据需要gasfee):
否则这么传输的话会报错的:
orders := []chainservice.OrderInfo{
//{OrderNumber: 10001, StartLuckNum: 1, Amount: 1},
{OrderNumber: 10002, StartLuckNum: 2, Amount: 2},
{OrderNumber: 10003, StartLuckNum: 4, Amount: 3},
{OrderNumber: 10004, StartLuckNum: 7, Amount: 1},
{OrderNumber: 10005, StartLuckNum: 8, Amount: 3},
{OrderNumber: 10006, StartLuckNum: 11, Amount: 1},
{OrderNumber: 10007, StartLuckNum: 12, Amount: 1},
{OrderNumber: 10008, StartLuckNum: 13, Amount: 3},
{OrderNumber: 10009, StartLuckNum: 16, Amount: 1},
{OrderNumber: 10010, StartLuckNum: 17, Amount: 2},
{OrderNumber: 10011, StartLuckNum: 19, Amount: 1},
{OrderNumber: 10010, StartLuckNum: 20, Amount: 2},
{OrderNumber: 10010, StartLuckNum: 22, Amount: 3},
{OrderNumber: 10010, StartLuckNum: 25, Amount: 4},
{OrderNumber: 10010, StartLuckNum: 29, Amount: 2},
}
标签:存储,roundInfo,OrderNumber,Amount,nifiNum,ton,StartLuckNum,msg,合约 From: https://www.cnblogs.com/zhanchenjin/p/18476057