首页 > 其他分享 >ton合约中的变量需要在运行结束之后才能存储到合约中

ton合约中的变量需要在运行结束之后才能存储到合约中

时间:2024-10-19 16:45:05浏览次数:1  
标签:存储 roundInfo OrderNumber Amount nifiNum ton StartLuckNum msg 合约

  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

相关文章

  • (环境篇日志-CVPR2024 ) Physical 3D Adversarial Attacks against Monocular Depth E
    题目:Physical3DAdversarialAttacksagainstMonocularDepthEstimationinAutonomousDriving作者:JunhaoZheng,ChenhaoLin*,JiahaoSun,ZhengyuZhao,QianLi,ChaoShen*单位:Xi’anJiaotongUniversity收录:CVPR2024论文:[Physical3DAdversarialAttacks......
  • “JsonConvert”同时存在于“Newtonsoft.Json.Net20, Version=3.5.0.0, Culture=neutr
    原因是两个dll冲突了。需要去掉一个。Newtonsoft.Json(也称为Json.NET)是一个流行的开源JSON框架,用于.NET,它以其高性能、易用性和广泛的功能而闻名。它支持丰富的数据操作和序列化属性设置,如自定义转换器、日期时间格式控制、命名策略等。Json.NET还提供了序列化特性,如JsonObjectA......
  • 存储
    卷容器中的文件在磁盘上是临时存放的,这给在容器中运行较重要的应用带来一些问题。当容器崩溃或停止时会出现一个问题。此时容器状态未保存,因此在容器生命周期内创建或修改的所有文件都将丢失。在崩溃期间,kubelet会以干净的状态重新启动容器。当多个容器在一个Pod中运行并......
  • Redis 集群:高效缓存与数据存储的利器
    在当今的互联网时代,数据的存储和处理速度至关重要。Redis作为一种高性能的内存数据库,广泛应用于各种场景。而Redis集群则进一步提升了Redis的可用性、扩展性和性能。本文将为你详细介绍Redis集群的简介以及三种模式。一、Redis集群简介Redis集群是由多个Redis......
  • 云存储图片生成缩略图开发
    作者:狼哥团队:坚果派团队介绍:坚果派由坚果等人创建,团队拥有12个华为HDE带领热爱HarmonyOS/OpenHarmony的开发者,以及若干其他领域的三十余位万粉博主运营。专注于分享HarmonyOS/OpenHarmony、ArkUI-X、元服务、仓颉。团队成员聚集在北京,上海,南京,深圳,广州,宁夏等地,目前已开发鸿蒙原......
  • Zabbix模板数据存储在哪里?
    Zabbix的模板数据存储在数据库的哪一个表里面?以MySQL数据库为例,在数据库zabbix中,其实模板数据存储在hosts这个表里面,而不是存在hosts_templates表里面。很多人一看到templates关键字,容易先入为主的以为这个表会存储模板的相关数据。但是实际上,hosts_templates表用于存储主机和模板......
  • k8s-Longhorn系统配置 20241017 -分布式存储
    目录一Longhorn存储部署1.1Longhorn概述1.2Longhorn部署1.5动态sc创建1.6测试PV及PVC1.7Ingress暴露Longhorn1.8确认验证附加Helm部署附0.1helm安装附0.2helm安装 回到顶部一Longhorn存储部署1.1Longhorn概述Longhorn是用于Kubernetes的......
  • THM-Vulnerability Capstone
    首先收集信息,获取版本号Whatisthenameoftheapplicationrunningonthevulnerablemachine?FuelCMSWhatistheversionnumberofthisapplication?1.4WhatisthenumberoftheCVEthatallowsanattackertoremotelyexecutecodeonthisapplicati......
  • cornerstone中RAFT的buffer的实现
    1.概览:谈到raft协议实现就绕不开网上流行的mit6.824,但其为go语言,官方没有lab的答案,框架也很晦涩难懂,且全网没有一个博客对其有清晰的解释,有的只是甩一堆名词然后直接贴没有任何注释的代码,非常不适合学习。但是github上面的cornerstone是纯c++实现的一个非常优雅且精简的raft协议......
  • ton tact合约中的map采用go的调用方式
    tact中的map结构:structRoundInfo{//Purchaserecordsquotient:map<Intasuint32,BuyInfo>;//keyissequencenumber//Orderanti-duplicationrecords,keyisordernumber,valueissequencenumberorders:map<Intasuint32,Intasuint16......