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

Ethereum transaction refactoring #624

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

esuwu
Copy link
Contributor

@esuwu esuwu commented Dec 13, 2021

No description provided.

return EthereumTransferWavesKind, nil
}

selectorBytes := data
Copy link
Member

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])
Copy link
Member

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 {
Copy link
Member

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.

Comment on lines +489 to +492
case *EthereumTransferAssetsErc20TxKind:
return nil
case *EthereumInvokeScriptTxKind:
return nil
Copy link
Member

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.

Comment on lines +183 to +185
res := new(big.Int).Div(tx.inner.value(), big.NewInt(int64(DiffEthWaves)))
tx.value = res.Int64()

Copy link
Member

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
Copy link
Member

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.

Comment on lines +162 to 167
// Ethereum representation
senderPK atomic.Value // *EthereumPublicKey
inner EthereumTxData //

// Waves representation
TxKind EthereumTransactionKind
Copy link
Member

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
Copy link
Member

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.

Comment on lines +403 to 405
func (tx *EthereumTransaction) ChainId() int64 {
return tx.chainID
}
Copy link
Member

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().

Comment on lines -401 to +420
func (tx *EthereumTransaction) Value() *big.Int { return copyBigInt(tx.inner.value()) }
func (tx *EthereumTransaction) Value() int64 { return tx.value }
Copy link
Member

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

Comment on lines +483 to +486
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())
}
Copy link
Member

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.

@nickeskov nickeskov added do not merge The PR is not ready to be merged temporary It's necessary at the moment, but it's going to be deleted/changed in the nearest future labels Jan 27, 2022
@nickeskov nickeskov marked this pull request as draft May 21, 2022 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not merge The PR is not ready to be merged temporary It's necessary at the moment, but it's going to be deleted/changed in the nearest future
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants