- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设我有一份契约(Contract)
...
pub struct Contract {
collection_a: Vector<String>,
}
在我部署这个版本之后,当我改变我的智能合约的数据结构时,例如
pub struct Contract {
collection_a: Vector<String>,
collection_b: Vector<String>,
}
我在与合约交互时遇到了错误
Failure [dev-1644158197214-15380220543819]: Error: {"index":0,"kind":{"ExecutionError":"Smart contract panicked: panicked at 'Cannot deserialize the contract state.: Custom { kind: InvalidInput, error: \"Unexpected length of input\" }', /workspace/.cargo/registry/src/github.com-1ecc6299db9ec823/near-sdk-3.1.0/src/environment/env.rs:786:46"}}
ServerTransactionError: {"index":0,"kind":{"ExecutionError":"Smart contract panicked: panicked at 'Cannot deserialize the contract state.: Custom { kind: InvalidInput, error: \"Unexpected length of input\" }', /workspace/.cargo/registry/src/github.com-1ecc6299db9ec823/near-sdk-3.1.0/src/environment/env.rs:786:46"}}
at Object.parseResultError (/home/gitpod/.nvm/versions/node/v16.13.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/utils/rpc_errors.js:31:29)
at Account.signAndSendTransactionV2 (/home/gitpod/.nvm/versions/node/v16.13.0/lib/node_modules/near-cli/node_modules/near-api-js/lib/account.js:160:36)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async scheduleFunctionCall (/home/gitpod/.nvm/versions/node/v16.13.0/lib/node_modules/near-cli/commands/call.js:57:38)
at async Object.handler (/home/gitpod/.nvm/versions/node/v16.13.0/lib/node_modules/near-cli/utils/exit-on-error.js:52:9) {
type: 'FunctionCallError',
context: undefined,
index: 0,
kind: {
ExecutionError: `Smart contract panicked: panicked at 'Cannot deserialize the contract state.: Custom { kind: InvalidInput, error: "Unexpected length of input" }', /workspace/.cargo/registry/src/github.com-1ecc6299db9ec823/near-sdk-3.1.0/src/environment/env.rs:786:46`
},
transaction_outcome: {
proof: [ [Object], [Object] ],
block_hash: '5mPRmggsyL9cNsgS4a6mzRT7ua9Y8SS8XJbW9psawdDr',
id: '8BeARer3UXLoZ3Vr22QAqkyzsp143D7FCtVssjyYxzs',
outcome: {
logs: [],
receipt_ids: [Array],
gas_burnt: 2427936651538,
tokens_burnt: '242793665153800000000',
executor_id: 'dev-1644158197214-15380220543819',
status: [Object],
metadata: [Object]
}
}
}
当我需要更新结构时,如何处理这种情况?
最佳答案
你要的是storage migration :
#[derive(BorshSerialize, BorshDeserialize)]
pub struct OldContract {
collection_a: Vector<String>,
}
#[near_bindgen]
#[derive(BorshSerialize, BorshDeserialize)]
pub struct Contract {
collection_a: Vector<String>,
collection_b: Vector<String>,
}
#[near_bindgen]
impl Contract {
#[private]
#[init(ignore_state)]
pub fn migrate() -> Self {
let old_storage: OldContract = env::state_read().expect("Couldn't read old state");
Self {
collection_a: old_storage.collection_a,
collection_b: Vec::new(),
}
}
}
首先使用此代码更新您的契约(Contract),然后使用契约(Contract) key 调用 migrate
方法。在下次升级时,您可以删除该方法和 OldContract
结构以节省存储空间。
您可能遇到的一个问题是不适合单个 block 的存储迁移。 AFAIK,没有解决方案。然而,Borsh 序列化是确定性的,因此只要您将数据结构保持为枚举,您就应该能够重新解释当前链存储并将迁移拆分为多个部分迁移。确保对此进行彻底测试,否则您将面临无法恢复地搞砸契约(Contract)状态的风险。
关于rust - 我应该如何处理 NEAR 协议(protocol)中的智能合约结构变更?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71008470/
我遇到了 following code : contract="*" 是什么意思? 不是每个 WCF 客户端或服务都必须指定契约(Contract)吗? 最佳答案 它用于服
我想通过 web3 用 pancakeswap testnet contarct 将一些 testnet bep20 token 交换到 busd(bep20)。 我查看了契约(Contract),但
我创建了 WCF 服务应用程序,在运行 WcfTestClient 之前没有错误.它需要 IMetadataExchange进行配置。 如何配置IMetadataExchange或避免使用? 错误:
我对 Kotlin 可空性有疑问,我想知道我是否能够通过契约(Contract)解决它。 对于这样的Java接口(interface):interface Action{ void execute(T
我有两个需要受契约(Contract)约束的 .NET 方。现在,party1 和 party2 需要能够相互调用一些方法(大部分是调用和报告结果)。我有双工契约(Contract),但双方没有使用
Scrapy 合约问题 我开始研究 scrapy 框架。也实现了一些蜘蛛 提取,但我无法为蜘蛛编写单元测试用例,因为契约(Contract) scrapy 提供的包文档没有正确的程序来编写 测试用例。
简而言之,hashCode合约,根据Java的object.hashCode(): 除非影响 equals() 的内容发生更改,否则哈希码不应更改 equals() 表示哈希码是 == 让我们假设主要
从 web3js 传递(javascript 对象数组)时出现错误, 以(结构数组)为参数的solidity函数。 你可以帮帮我吗? 下面是代码和错误 // web3js code let slcte
使用Spring云合约来验证我的生产者和消费者之间的合约。在我的消费者 Controller 中,我使用 Feign 客户端调用另一个微服务方法来获取一些数据。但现在在 Spring Cloud 合约
我正在尝试让一个简单的基于 Acumatica 契约的 SOAP API Get() 或 GetList() 调用工作,但我得到的只是一个错误: System.ServiceModel.FaultEx
关于如何为使用 @RequestBody 注释并以字符串集合作为参数的方法编写契约的问题。我有以下方法: @PostMapping(path = "/some/uri", produces =
Wiremock 记录以下请求不匹配: WireMock : Request was not matched: { "url
通常我通过导入外部契约(Contract)的接口(interface)并生成契约(Contract)的“局部变量”来调用外部契约(Contract),一旦我需要它。像这样的东西: import "./
我正在尝试编写一个断言函数来检查给定对象是否属于 T 类型: @UseExperimental(ExperimentalContracts::class) inline fun assertIsIn
当我使用 gradle 构建项目时,我不断收到 Spring Cloud Contract 的此错误。有什么线索吗? * What went wrong: Execution failed for t
我尝试创建一个 MQL4 脚本(一种几乎与 C++ 相关的语言,MQL4),我想在其中将 double 值分为 9 个部分,其中分数不相等,但增加 我当前的代码尝试这样做(伪代码): Lots1
背景 我在 Solidity 中编写了一个以太坊智能合约语言。为了进行测试,我可以使用 Ganache 运行本地节点并使用 truffle migrate 在其上部署我的合约。 要求 我想使用 Jav
我正在尝试将 Spring 契约(Contract) stub jar 设置为带有使用者的胖 jar 或我的服务可以向其发送请求并最终接收评估响应的 http REST 端点。 理想情况下,我更喜欢后
我是 DAML 新手,我想使用 Java 绑定(bind)、Bot API 查询所有 Activity 合约,并将它们保存到数据库(或内存中)以供将来查询。 根据文档,LedgerView 可以跟踪内
我遇到了“您尚未配置 MockMVC 实例”的问题。 “mvn全新安装”时的异常。 运行 org.springframework.cloud.contract.verifier.tests.Contr
我是一名优秀的程序员,十分优秀!