Solidity
編譯時出錯:堆棧太深
這是我的程式碼,我在函式中有數組而不是 16 個變數,請在我錯的地方提供幫助。
struct Escrow { bytes16 contractID; uint256 sellingTokenAmt; uint256 feeAmtInSellingToken; uint256 arbitrationFees; uint256 paymentWindowInSeconds; uint256 contractLifespanInSec; uint256 disputeWindowInSeconds; uint256 buyingTokenAmt; uint256 buyerAddress1Amt; uint256 buyerAddress2Amt; uint256 buyerAddress3Amt; uint256 createdAt; uint256 updatedAt; uint256 disputedAt; address sellerAddress; address buyerAddress1; address buyerAddress2; address buyerAddress3; address feeAddress; address arbitratorAddress; address sellingToken; string buyingToken; bool isDisputed; bool createdBy; string sellerPaymentDetails; } function createEscrow(bytes16 _contractId, uint256[] calldata _intValues, string calldata _buyingToken, address[] calldata _addresses, address token, string calldata _sellerPaymentDetails ) payable external { bytes32 _tradeHash = keccak256(abi.encodePacked(_contractId)); Escrow storage escrow = escrows[_tradeHash]; uint256 tokenBalance = ERC20Interface(token).balanceOf(msg.sender); require(escrow.contractID!=_contractId, "Already in Trading."); require (_intValues[0] > 0, "Please add valid amount"); require (_intValues[0] > 0, "Please add valid amount"); require(tokenBalance >=_intValues[0], "Insufficient balance."); require(ERC20Interface(token).transferFrom(_addresses[0], address(this), _intValues[0])); escrows[_tradeHash] = Escrow(_contractId, _intValues[0], _intValues[1], _intValues[2], _intValues[3], _intValues[4], _intValues[5], _intValues[6], _intValues[7], _intValues[8], _intValues[9], now, now, now ,_addresses[0], _addresses[1], _addresses[2], _addresses[3], _addresses[4], _addresses[5], token, _buyingToken, false, true, _sellerPaymentDetails); totlaEscrows++; emit Created (_tradeHash); }
錯誤說明了一切,您需要分解結構數據。要麼將其分離到不同的結構、契約或保留一些數據鏈(數據庫),使用唯一參數進行連接/連結並將該唯一參數保存到結構中。
另一個解決方案是我為另一個項目所做的,我必須保存許多變數,包括單個人的文件,所以我只是將所有內容上傳到 IPFS,並且只將 IPFS 雜湊保存到我的智能合約中的個人數據中。(與在智能合約中儲存數據庫 ID 的原理相同)