lemooljiang avatar

合约中堆栈太深引发的错误 / 学习智能合约#24

lemooljiang

Published: 20 Sept 2020 › Updated: 20 Sept 2020

合约中堆栈太深引发的错误 / 学习智能合约#24

stack.jpg

今天在设计一个场外合约时遇到了一个错误,如上图所示:堆栈太深!

struct OrderMessage
    {
        uint256 orderNumber;
        string typeOfPayment;
        string collectingAccount;
        string sellerSteem;
        address sellerTron;
        string buyerSteem;
        address buyerTron;
        uint256 amount;
        uint256 price;
        uint256 orderCreated;
        uint256 orderValidity;
        uint256 submitTime;
        State state;
    }

如上所示,如果一个结构体有太多变量,或是函数有太多参数就会引发堆栈太深的错误,必须要删除些变量才行。在以太坊中这个上限是16个,在波场中13个就会引发。

所以,在设计中不能真把区块链当数据库来存储,很多变量应该打包在一个变量中,或是用IPFS来存储大部分的变量,区块链只存储必要的数据,这样才是一个好的方案。

Leave 合约中堆栈太深引发的错误 / 学习智能合约#24 to:

Written by

Designer , Poet , Technology enthusiasts

Read more #smartcontract posts


Best Posts From lemooljiang

We have not curated any of lemooljiang's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From lemooljiang