-
Notifications
You must be signed in to change notification settings - Fork 35
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
Ethereum transaction refactoring #624
base: master
Are you sure you want to change the base?
Conversation
…atform/gowaves into ethereum-transaction-refactoring
return EthereumTransferWavesKind, nil | ||
} | ||
|
||
selectorBytes := data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unnecessary variable
if len(data) < ethabi.SelectorSize { | ||
return 0, errors.Errorf("length of data from ethereum transaction is less than %d", ethabi.SelectorSize) | ||
} | ||
selector, err := ethabi.NewSelectorFromBytes(selectorBytes[:ethabi.SelectorSize]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data[:ethabi.SelectorSize]
does the same. Maybe you meant selectorBytes := data[:ethabi.SelectorSize]
. Correct me if I'm wrong
if err != nil { | ||
return nil, errors.Errorf("failed to parse ethereum data") | ||
} | ||
if len(decodedData.Inputs) != ethabi.NumberOfERC20TransferArguments { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is unnecessary. ethabi.GetERC20TransferArguments
does the same check inside.
case *EthereumTransferAssetsErc20TxKind: | ||
return nil | ||
case *EthereumInvokeScriptTxKind: | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merge this cases or rewrite whole switch to if...else.
res := new(big.Int).Div(tx.inner.value(), big.NewInt(int64(DiffEthWaves))) | ||
tx.value = res.Int64() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should handle it res doesn't fit into int64
value even in tests.
TxKind EthereumTransactionKind | ||
value int64 | ||
chainID int64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use proto.Scheme
type instead of int64
. And for WAVES network correct naming is sheme
, not chainID
.
// Ethereum representation | ||
senderPK atomic.Value // *EthereumPublicKey | ||
inner EthereumTxData // | ||
|
||
// Waves representation | ||
TxKind EthereumTransactionKind |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use different naming for Ethereum representation
fields and Waves representation
fields. I think it would be better if you create special struct for valid waves representation.
@@ -250,6 +274,7 @@ func (tx *EthereumTransaction) Validate(scheme Scheme) (Transaction, error) { | |||
return nil, errs.NewFeeValidation("insufficient fee") | |||
} | |||
// too many waves (this check doesn't exist in scala) | |||
// TODO I'm not sure this is should be checked for all eth tx kinds. Only for transfer waves kind |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's valid. Negative wavelets amount is invalid. It must be zero or greater.
func (tx *EthereumTransaction) ChainId() int64 { | ||
return tx.chainID | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should change return type to proto.Scheme
. And I think it would be better if you rename this method to Scheme()
.
func (tx *EthereumTransaction) Value() *big.Int { return copyBigInt(tx.inner.value()) } | ||
func (tx *EthereumTransaction) Value() int64 { return tx.value } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment says that Value returns the ether amount of the transaction.
. You return wavelets
res := new(big.Int).Div(tx.inner.value(), big.NewInt(int64(DiffEthWaves))) | ||
if ok := res.IsInt64(); !ok { | ||
return errors.Errorf("failed to convert amount from ethreum transaction (big int) to int64. value is %d", tx.Value()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can easily use previous version for of EthereumWeiToWavelet
function for conversion.
No description provided.