contract-metadata icon indicating copy to clipboard operation
contract-metadata copied to clipboard

## Proposed changes

Open Mortiemi opened this issue 1 year ago • 0 comments

Proposed changes

  • Harden the kaia_getTotalSupply API added in https://github.com/klaytn/klaytn/pull/2148.

  • TotalSupply API partially works even when some information isn't available.

  • When the state trie isn't available at the given block (e.g. pruning node), do not return zeroBurn, deadBurn, totalBurnt, totalSupply. Not returning totalSupply to prevent misinformation.

     kaia.getTotalSupply(128)
    
     burntFee: "0x0",
     deadBurn: null,
     error: "cannot determine canonical (0x0, 0xdead) burn amount: missing trie node d158d63e7624b0a16f45d61c231301e0d1d5b39114e1941daf5abab9c2eb0884 (path )",
     kip103Burn: "0x0",
     kip160Burn: "0x0",
     number: "0x80",
     totalBurnt: null,
     totalMinted: "0x204fcea0db2b93eaf0000000",
     totalSupply: null,
     zeroBurn: null
    
    
  • When the TreasuryRebalance (KIP-103 or KIP-160) has been executed but the memo is not stored via the finalizeContract() function, do not return kip103Burn and/or kip160Burn, totalBurnt, totalSupply. Not returning totalSupply to prevent misinformation.

     klay.getTotalSupply(1)
    
     burntFee: "0x0",
     deadBurn: "0x0",
     error: "cannot determine rebalance (kip103, kip160) burn amount: no contract code at given address\ncannot determine rebalance (kip103, kip160) burn amount: no contract code at given address",
     kip103Burn: null,
     kip160Burn: null,
     number: "0x1",
     totalBurnt: null,
     totalMinted: "0x446c3b15f9926687d2c40534fdb564000000000000",
     totalSupply: null,
     zeroBurn: "0x0"
    
    
    • But don't worry. Regardless of the requested block, the API reads the memo from the latest block. Once the memo is stored at some point, the previous block's total supply also shows up correctly.
  • In all cases, the API additionally prints the block number

    
     burntFee: "0x29ec817ffd11a9cd3a4b3",
     deadBurn: "0x40c166a428511ad626d306",
     kip103Burn: "0x111d0449fb2a238eca3b1720",
     kip160Burn: "0x0",
     number: "0x93295ce",
     totalBurnt: "0x11606478b75245c43d358ed9",
     totalMinted: "0x249a79581de10f4cd3000000",
     totalSupply: "0x133a14df668ec98895ca7127",
     zeroBurn: "0x0"
    
    

Types of changes

Please put an x in the boxes related to your change.

  • [x] Bugfix
  • [ ] New feature or enhancement
  • [ ] Others

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • [x] I have read the CONTRIBUTING GUIDELINES doc
  • [x] I have signed the CLA
  • [x] Lint and unit tests pass locally with my changes ($ make test)
  • [x] I have added tests that prove my fix is effective or that my feature works
  • [ ] I have added necessary documentation (if appropriate)
  • [ ] Any dependent changes have been merged and published in downstream modules

Related issues

https://github.com/klaytn/klaytn/issues/1617

Further comments

Originally posted by @blukat29 in https://github.com/klaytn/klaytn/pull/2178

Mortiemi avatar May 22 '24 06:05 Mortiemi