Closed 9876691 closed 5 years ago
Test Case 1.
Initialise the EthereumTransaction.new with the following data.
to = 0xaA429FeDC40Eaa82894E5a9d6a678Ea57ac19DAf
from = 0x46FC2341DC457BA023cF6d60Cb0729E5928A81E6
amount = 1000000000000000
GAS_LIMIT = 30_000
GAS_PRICE = (0.00000002 * 1_000_000_000_000_000_000).to_i
Call to_hex you should get the following result.
0xeb0c8504a817c80082753094aa429fedc40eaa82894e5a9d6a678ea57ac19daf87038d7ea4c6800000808080
Test Case 2
Initialise the eth_tx = EthereumTransaction.new with the a hexedecimal transaction.
0xeb0c8504a817c80082753094aa429fedc40eaa82894e5a9d6a678ea57ac19daf87038d7ea4c6800000808080
Then
eth_tx.to.should eq("0xaA429FeDC40Eaa82894E5a9d6a678Ea57ac19DAf")
eth_tx.amount.should eq(1000000000000000)
eth_tx.to_hex should bring back the same hex as before i.e.
0xeb0c8504a817c80082753094aa429fedc40eaa82894e5a9d6a678ea57ac19daf87038d7ea4c6800000808080
Test Case 3
Initialise the eth_tx = EthereumTransaction.new with the a hexedecimal transaction.
0xeb0c8504a817c80082753094aa429fedc40eaa82894e5a9d6a678ea57ac19daf87038d7ea4c6800000808080
eth_tx.hash_to_sign.should eq("b243b9b6e4a7865e8c5429653e3e2153e26424ad59ea96768981a01cf13944f5")
This is basically to re-write a ruby class into crystal. https://github.com/onchain/onchain-gem/blob/master/lib/onchain/ethereum.rb
Create a class called EthereumTransaction that implements the transaction interface. i..e
Implement an initialise method that creates the underlying representation from hexidecimal, the initialise doesn't need to set the r,s,v properties
implement the to_hex method.
Implement the hash_to_sign method. This is the keccak 256 hash of the transaction.
Implement a sign method. This takes the r,s,v values and adds them. After which calling to_hex will create a fully signed ethereum transaction.
You can see the way this fits together in the https://github.com/onchain/paper-wallet-spender/blob/master/src/onchain/protocol/zcash_transaction.cr class.