Ride4Dapps: TypeError Не удается прочитать свойство «длина» неопределенного значения в invokeScript

Я пытаюсь выполнить пример wallet.ride, и у меня есть некоторые проблемы с этим:

широковещательная передача (invokeScript ({contractAddress: адрес (env.accounts [1]), вызов: {функция: "депозит", аргументы: []}, платеж: [{сумма: 300000000, актив: null }]}))

TypeError: невозможно прочитать свойство «длина» неопределенного

Как это исправить?

# In this example multiple accounts can deposit their funds and safely take them back, no one can interfere with this.
# An inner state is maintained as mapping `address=>waves`.

# You can try this contract by following commands in the IDE (ide.wavesplatform.com)
# Run commands as listed below
# From account #0:
#      broadcast(transfer({recipient:address(env.accounts[1]), amount: 1000000000}))
#      broadcast(transfer({recipient:address(env.accounts[2]), amount: 1000000000}))
# From account #1:
#      deploy()
# From account #2:
#      broadcast(invokeScript({contractAddress: address(env.accounts[1]), call:{function:"deposit",args:[]}, payment: [{amount: 300000000, asset:null }]}))
#      # observe state and balance of account(1)
#      broadcast(invokeScript({contractAddress: address(env.accounts[1]), call:{function:"deposit",args:[]}, payment: [{amount: 200000000, asset:null }]}))
#      # observe state and balance of account(1)
#      broadcast(invokeScript({contractAddress: address(env.accounts[1]), call:{function:"withdraw",args:[{type:"integer", value: 600000000}]}, payment: []}))
#      # observe error, nothing changed
#      broadcast(invokeScript({contractAddress: address(env.accounts[1]), call:{function:"withdraw",args:[{type:"integer", value: 400000000}]}, payment: []}))
#      # observe state and balance of account(1)


{-# STDLIB_VERSION 3 #-}
{-# CONTENT_TYPE DAPP #-}
{-# SCRIPT_TYPE ACCOUNT #-}

@Callable(i)
func deposit() = {
   let pmt = extract(i.payment)
   if (isDefined(pmt.assetId)) then throw("can hodl waves only at the moment")
   else {
        let currentKey = toBase58String(i.caller.bytes)
        let currentAmount = match getInteger(this, currentKey) {
            case a:Int => a
            case _ => 0
        }
        let newAmount = currentAmount + pmt.amount
        WriteSet([DataEntry(currentKey, newAmount)])
   }
}

@Callable(i)
func withdraw(amount: Int) = {
        let currentKey = toBase58String(i.caller.bytes)
        let currentAmount = match getInteger(this, currentKey) {
            case a:Int => a
            case _ => 0
        }
        let newAmount = currentAmount - amount
     if (amount < 0)
            then throw("Can't withdraw negative amount")
    else if (newAmount < 0)
            then throw("Not enough balance")
            else ScriptResult(
                    WriteSet([DataEntry(currentKey, newAmount)]),
                    TransferSet([ScriptTransfer(i.caller, amount, unit)])
                )
    }


@Verifier(tx)
func verify() = {
    true
}

Я использую ide.wavesplatform.com, поэтому кажется, что env.SEED иногда может быть «неопределенным». Чтобы предотвратить любые другие сбои «env», я попытаюсь повторить это локально, используя node.js.

Aleksei Pupyshev 10.04.2019 11:40
1
1
64
1
Перейти к ответу Данный вопрос помечен как решенный

Ответы 1

Ответ принят как подходящий

Решено! посмотрите: платеж = 100000000 и dappAddress вместо адрес договора

# You can try this contract by following commands in the IDE (ide.wavesplatform.com)
# Run commands as listed below
# From account #0:
#      broadcast(transfer({recipient:address(env.accounts[1]), amount: 100000000, fee: 100000000}))
#      broadcast(transfer({recipient:address(env.accounts[2]), amount: 100000000, fee: 100000000}))
# From account #1:
#      deploy()
# From account #2:
#      broadcast(invokeScript({dappAddress: address(env.accounts[1]), call:{function:"deposit",args:[]}, payment: [{amount: 300000000, asset:null }]}))
#      # observe state and balance of account(1)

Другие вопросы по теме