Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Elrond blockchain #929

Merged
merged 12 commits into from
Apr 29, 2020
Merged

Add Elrond blockchain #929

merged 12 commits into from
Apr 29, 2020

Conversation

andreibancioiu
Copy link
Contributor

@andreibancioiu andreibancioiu commented Apr 23, 2020

Description

Extended Wallet-core with blockchain & coin Elrond.

Testing instructions

  • interacting with walletconsole
  • running the tests

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist

  • Prefix PR title with [WIP] if necessary.
  • Add tests to cover changes as needed.
  • Update documentation as needed.
  • If there is a related Issue, mention it in the description (e.g. 'Fixes Adopt Zilliqa to bech32 address format #444 ).

New blockchain checklist

  • Add the coin definition to coins.json.
  • Add coin dispatcher to src/Coin.cpp
  • Create tests in tests/Elrond/TWCoinTypeTests.cpp
  • Implement Entry.cpp
  • Implement Address.cpp
  • Implement Transaction.cpp if necessary. Was not necessary.
  • Implement Signer.cpp
  • Write test: mnemonic phrase - > Address derivation test. Put this test in CoinTests.cpp TWHDWalletTests.cpp.
  • Transaction signing tests, at least one mainnet transaction test.
  • Add stake, unstake, get rewards tests if the blockchain is PoS like. Will be added later in time.
  • Implement C interface in src/interface Not applicable.
  • Add tests for TWAnyAddress
  • Add tests for TWAnySigner
  • Add tests in ElrondTests.swift
  • Validate generated code in Android project. Write integration tests. Maiar Android Wallet.
  • Validate generated code in iOS project. Write integration tests. Maiar iOS Wallet.
  • Extend test: CoinAddressDerivationTests.cpp
  • Extend test: CoinAddressValidationTests.cpp
  • Extend test: TWHRPTests.cpp
  • Extend test CoinAddressDerivationTests.kt
  • Extend test CoinAddressDerivationTests.swift
  • Upload coin icon to trustwallet/assets if necessary.

@andreibancioiu andreibancioiu changed the title Add elrond [WIP] Add elrond Apr 23, 2020
@codecov
Copy link

codecov bot commented Apr 23, 2020

Codecov Report

Merging #929 into master will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #929      +/-   ##
==========================================
+ Coverage   93.30%   93.35%   +0.04%     
==========================================
  Files         418      424       +6     
  Lines       12167    12241      +74     
==========================================
+ Hits        11353    11427      +74     
  Misses        814      814              
Impacted Files Coverage Δ
src/Coin.cpp 98.59% <100.00%> (+<0.01%) ⬆️
src/Elrond/Address.cpp 100.00% <100.00%> (ø)
src/Elrond/Address.h 100.00% <100.00%> (ø)
src/Elrond/Entry.cpp 100.00% <100.00%> (ø)
src/Elrond/Entry.h 100.00% <100.00%> (ø)
src/Elrond/Serialization.cpp 100.00% <100.00%> (ø)
src/Elrond/Signer.cpp 100.00% <100.00%> (ø)
src/interface/TWAnyAddress.cpp 94.66% <100.00%> (+0.22%) ⬆️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7dde1a5...71b5023. Read the comment docs.

@andreibancioiu andreibancioiu changed the title [WIP] Add elrond Add Elrond blockchain Apr 23, 2020
@andreibancioiu andreibancioiu marked this pull request as ready for review April 23, 2020 14:32
@auto-assign auto-assign bot requested review from optout21 and hewigovens April 23, 2020 14:33
@hewigovens
Copy link
Contributor

Hi, have you checked the integration criteria? pr won't be accepted if not meets

Copy link
Contributor

@hewigovens hewigovens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a few comments, can you rebase master? CI should be fixed

@@ -43,6 +43,7 @@ This list is generated from [./coins.json](../coins.json)
| 461 | Filecoin | FIL | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/filecoin/info/logo.png" width="32" /> | <https://filecoin.io/> |
| 500 | Theta | THETA | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/theta/info/logo.png" width="32" /> | <https://www.thetatoken.org> |
| 501 | Solana | SOL | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/solana/info/logo.png" width="32" /> | <https://solana.com> |
| 508 | Elrond | ERD | <img src="https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/elrond/info/logo.png" width="32" /> | <https://elrond.com/> |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logo.png is 404

Copy link
Contributor Author

@andreibancioiu andreibancioiu Apr 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, we did not open a pull request against the repository trustwallet/assets yet, but we are bootstrapping this flow as well.

src/Elrond/Address.h Outdated Show resolved Hide resolved
src/Elrond/Serialization.cpp Outdated Show resolved Hide resolved
src/Elrond/Serialization.cpp Show resolved Hide resolved
src/Elrond/Serialization.cpp Outdated Show resolved Hide resolved
tests/Elrond/TWCoinTypeTests.cpp Outdated Show resolved Hide resolved
string value = 2;
string receiver = 3;
string sender = 4;
uint64 gas_price = 5;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elrond decimals is 18, overflow if you use type uint64?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good question. However we expect gas_price to be much, much lower than max(uint64) for any transaction, with respect to our network's economics. The gas_price, chosen by the issuer of the transaction, is per gas unit - while gas_limit (the number of gas units) is constrained to have a quite high (~50000) lower bound, and thus a very large gas_price would be prohibitive (balance exhaustion).

Once the transaction reaches the network, we use big numbers to perform calculations on this matter.

src/proto/Elrond.proto Outdated Show resolved Hide resolved
swift/Tests/Blockchains/ElrondTests.swift Show resolved Hide resolved
auto signature = output.signature();
auto signedTransaction = output.signed_transaction();
auto expectedSignature = "b88ad2fe98a7316ea432a0a76c18cd87200fe75f27a8f053ea6532b40317dbec5136c5463aef132ae951b7e60d45d921caaa5903e70821dcda98f237d4ec4308";
auto expectedSignedTransaction = (boost::format(R"({"nonce":0,"value":"0","receiver":"%1%","sender":"%2%","gasPrice":200000000000000,"gasLimit":500000000,"data":"foo","signature":"%3%"})") % BOB_BECH32 % ALICE_BECH32 % expectedSignature).str();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a valid tx in block explorer?

Copy link
Contributor Author

@andreibancioiu andreibancioiu Apr 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is - the encoded transaction to be sent to the blockchain / network would look like this:

{
    "nonce": 0,
    "value": "0",
    "sender": "erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz",
    "receiver": "erd1cux02zersde0l7hhklzhywcxk4u9n4py5tdxyx7vrvhnza2r4gmq4vw35r",
    "gasPrice": 200000000000000,
    "gasLimit": 500000000,
    "data": "foo",
    "signature": "b88ad2fe98a7316ea432a0a76c18cd87200fe75f27a8f053ea6532b40317dbec5136c5463aef132ae951b7e60d45d921caaa5903e70821dcda98f237d4ec4308"
}

The computed hash (returned upon invoking the API) is cbecce3712064fe8b14bd668f02cf348d4ee5e4c73836d0a7e25482e5d0056d9, and the link in block explorer would be:

https://explorer.elrond.com/transactions/cbecce3712064fe8b14bd668f02cf348d4ee5e4c73836d0a7e25482e5d0056d9

The link above is currently available (and will be until a hard reset of our testnet).

Does this answer the question?

@andreibancioiu
Copy link
Contributor Author

@hewigovens thanks a lot for your review! We have applied the fixes and added some responses.

@hewigovens hewigovens merged commit 02eab8a into trustwallet:master Apr 29, 2020
@andreibancioiu andreibancioiu deleted the add-elrond branch May 7, 2020 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adopt Zilliqa to bech32 address format
4 participants