Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Alice checks the wallet balance by deploying contract, that contains printing of wallet balance to stdout, to e.g. validator node0.testnet.rchain-dev.tk (choose validator that should propose soon to minimise waiting time).
    rnode --grpc-host node0.testnet.rchain-dev.tk deploy --phlo-limit 100000 --phlo-price 1 --private-key 4021c7b19e7442cd299b5d541761ab86af34fcb74f24f5cd44360838d19618b7 alice_checks_balance.rho

    Code Block
    titlealice_checks_balance.rho
    new 
      rl(`rho:registry:lookup`), stdout(`rho:io:stdout`), 
      revVaultCh, vaultCh, balanceCh, log
    in {
      rl!(`rho:rchain:revVault`, *revVaultCh) |
      for (@(_, revVault) <- revVaultCh) {
        match "11112KDmzrKHjGRv43JqL1H7NiuwViQVx99EwacQdsPKBEm7xZgyVk" {
          revAddress => {
            @revVault!("findOrCreate", revAddress, *vaultCh) |
            for (@(true, vault) <- vaultCh) {
              @vault!("balance", *balanceCh) |
              for (@balance <- balanceCh) {
                log!("Balance of " ++ revAddress ++ " is ${balance}."%%{"balance":balance})
              }
            }
          }
        }
      } |
    
      contract log(@data) = {
        stdout!("COST ACCOUNTING TEST: Alice deploys. " ++ data)
      }
    }


  2. When validator proposes block, it sends it to all peers including validator that logs you are listening to. During replay it will print Alice's wallet balance. Write down Observe that number.
  3. Deploy check balance contract several times to subsequent validators (e.g. node2, node3, node4, one deploy per validator), observe that Alice's balance is decreasing when node you are listening to replays new blocks. 
  4. Alice's friend, Bob, who has no REVs and even do not have a wallet, ask her to create wallet for him with address 1111iNXW2k2S3S5bWL3W8w87itK1ky3y1ywySFBt9DkfPiZYo3KNU, so Alice deploys

    Code Block
    titlealice_creates_wallet.rho
    new 
      rl(`rho:registry:lookup`), stdout(`rho:io:stdout`), 
      revVaultCh, vaultCh, balanceCh, log
    in {
      rl!(`rho:rchain:revVault`, *revVaultCh) |
      for (@(_, revVault) <- revVaultCh) {
        match "1111iNXW2k2S3S5bWL3W8w87itK1ky3y1ywySFBt9DkfPiZYo3KNU" {
          revAddress => {
            @revVault!("findOrCreate", revAddress, *vaultCh) |
            for (@(true, vault) <- vaultCh) {
              @vault!("balance", *balanceCh) |
              for (@balance <- balanceCh) {
                log!("Wallet " ++ revAddress ++ " created. Balance is ${balance}."%%{"balance":balance})
              }
            }
          }
        }
      } |
    
      contract log(@data) = {
        stdout!("COST ACCOUNTING TEST: Alice creates wallet for Bob. " ++ data)
      }
    }

    You should observe in logs, that wallet with zero balance is created.

...