Add toSignature(Transaction) and getSender(Transaction) local procs

This commit is contained in:
coffeepots 2018-08-23 17:52:54 +01:00 committed by zah
parent 3f1e140d59
commit d901c20bb2
1 changed files with 23 additions and 1 deletions

View File

@ -385,7 +385,6 @@ proc setupP2PRPC*(node: EthereumNode, rpcsrv: RpcServer) =
accountGas = 0
populateTransactionObject(transaction, txHash, txCount, quantity, header, accountGas)
rpcsrv.rpc("eth_getTransactionByBlockNumberAndIndex") do(quantityTag: string, quantity: int) -> TransactionObject:
## Returns information about a transaction by block number and transaction index position.
##
@ -409,6 +408,29 @@ proc setupP2PRPC*(node: EthereumNode, rpcsrv: RpcServer) =
accountGas = 0
populateTransactionObject(transaction, txHash, txCount, quantity, header, accountGas)
template toSignature(transaction: Transaction): Signature =
var bytes: array[65, byte]
bytes[0..31] = cast[array[32, byte]](transaction.R)
bytes[32..63] = cast[array[32, byte]](transaction.S)
#[
TODO: In the yellow paper:
It is assumed that v is the recovery id, a 1 byte value
specifying the sign and finiteness of the curve point; this
value is in the range of [27,30].
Does this need to be checked that it is [0, 1] and inc by 27?
]#
# TODO: Ugly casting below, is there a better way/helper func?
bytes[64] = (cast[uint64](transaction.V.data.lo) and 0xff'u64).uint8
initSignature(bytes)
proc getSender(transaction: Transaction): EthAddress =
let
txHash = transaction.rlpHash
sig = transaction.toSignature()
pubKey = recoverKeyFromSignature(sig, txHash)
const pubKeySize = 64
result[0..19] = pubKey.data[pubKeySize - 20 .. pubKeySize - 1]
proc populateReceipt(receipt: Receipt, cumulativeGas: GasInt, transaction: Transaction, txIndex: int, blockHeader: BlockHeader): ReceiptObject =
result.transactionHash = transaction.rlpHash
result.transactionIndex = txIndex