-
Notifications
You must be signed in to change notification settings - Fork 6
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
WIP: add func BuildTxWithoutKeyDao for Avata #40
Open
ajiang55
wants to merge
23
commits into
main
Choose a base branch
from
sxj/test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
bf2dbb8
Merge pull request #30 from irisnet/zx/remove_cache
cyilong 4e406b8
Merge pull request #32 from irisnet/zx/remove_cache
prolenking f8488f2
add evm
aofengli 18c6d89
cache
aofengli d34d060
add evm broadcact
aofengli 6974c08
query tx add data feiled
aofengli 58b3f4d
stash
ajiang55 163759b
Merge pull request #35 from irisnet/cyl/fix-parse-block
cyilong 450db2e
stash
ajiang55 16966ea
stash
ajiang55 1841085
stash
ajiang55 37ff93e
add buildtx for avata
ajiang55 311a4d8
Merge branch 'shedlon/wenchangchain-develop' of github.com:irisnet/co…
ajiang55 22a04f7
fix key_dao
ajiang55 de5fc87
fix buildtxwithoutkeydao
ajiang55 79648fd
fix buildtxwithoutkeydao
ajiang55 338823e
fix buildtxwithoutkeydao
ajiang55 68bd86b
stash
ajiang55 4c6e81b
Merge branch 'main' of github.com:irisnet/core-sdk-go into sxj/test
ajiang55 041b7ff
fix buildtxwithoutkeydao
ajiang55 1fc63eb
fix buildtxwithoutkeydao
ajiang55 0b33ecd
fix BuildTx and SetTxSignature, add EstimateTxSize
ajiang55 9082c23
Merge pull request #41 from irisnet/sxj/test2
ajiang55 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package ethermint | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
codectypes "github.com/irisnet/core-sdk-go/common/codec/types" | ||
evmtypes "github.com/irisnet/core-sdk-go/ethermint/x/evm/types" | ||
sdktypes "github.com/irisnet/core-sdk-go/types" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
type Client struct { | ||
sdktypes.BaseClient | ||
txConfig sdktypes.TxConfig | ||
} | ||
|
||
// NewClient grant NewClient | ||
func NewClient(bc sdktypes.BaseClient, txConfig sdktypes.TxConfig) Client { | ||
return Client{ | ||
BaseClient: bc, | ||
txConfig: txConfig, | ||
} | ||
} | ||
|
||
func (cli *Client) RegisterInterfaceTypes(registry codectypes.InterfaceRegistry) { | ||
evmtypes.RegisterInterfaces(registry) | ||
} | ||
|
||
func (cli *Client) BuildEvmTx(hexData string, feePayerAddr string, evmDemon string) ([]byte, error) { | ||
data, err := hexutil.Decode(hexData) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to decode ethereum tx hex bytes") | ||
} | ||
msg := &evmtypes.MsgEthereumTx{} | ||
if err := msg.UnmarshalBinary(data); err != nil { | ||
return nil, err | ||
} | ||
if err := msg.ValidateBasic(); err != nil { | ||
return nil, err | ||
} | ||
if len(feePayerAddr) > 0 { | ||
msg.SetFeePayer(feePayerAddr) | ||
} | ||
|
||
builder := cli.txConfig.NewTxBuilder() | ||
tx, err := msg.BuildTx(builder, evmDemon) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return cli.txConfig.TxEncoder()(tx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package ethermint | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/gogo/protobuf/proto" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
|
||
sdk "github.com/irisnet/core-sdk-go" | ||
"github.com/irisnet/core-sdk-go/common/crypto" | ||
evmtypes "github.com/irisnet/core-sdk-go/ethermint/x/evm/types" | ||
"github.com/irisnet/core-sdk-go/types" | ||
sdktypes "github.com/irisnet/core-sdk-go/types" | ||
"github.com/irisnet/core-sdk-go/types/store" | ||
) | ||
|
||
func TestError(t *testing.T) { | ||
hex := "0AFB140A1F2F65746865726D696E742E65766D2E76312E4D7367457468657265756D547812D7140A4230783264343739623930346663313034356265613936633236303035383136343166306434306137336662396333336334313738653363326533333766386633636412C0020A2A3078414132343546336138313865303961383365623431333135613261633963303662663537616339411242307831636633623033613663663139666132626162613464663134386539646361626564656137663861356330373834306532303765356330383962653935643365124230783030303030303030303030303030303030303030303030303835316130336438306331363130613763646165366635653039616139373065323739383766636520B8A8562A423078326434373962393034666331303435626561393663323630303538313634316630643430613733666239633333633431373865336332653333376638663363643A423078633333386136663333616565393930653032336433383632643333303261666566303066313032353365656630393435333832323732613131393163646332621286030A2A30784141323435463361383138653039613833656234313331356132616339633036626635376163394112423078386265303037396335333136353931343133343463643166643061346632383431393439376639373232613364616166653362343138366636623634353765301242307830303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030124230783030303030303030303030303030303030303030303030306535346535316137613438613962343634636164383233636438346436356133346365626461626420B8A8562A423078326434373962393034666331303435626561393663323630303538313634316630643430613733666239633333633431373865336332653333376638663363643A4230786333333861366633336165653939306530323364333836326433333032616665663030663130323533656566303934353338323237326131313931636463326240011286030A2A30784141323435463361383138653039613833656234313331356132616339633036626635376163394112423078386265303037396335333136353931343133343463643166643061346632383431393439376639373232613364616166653362343138366636623634353765301242307830303030303030303030303030303030303030303030303065353465353161376134386139623436346361643832336364383464363561333463656264616264124230783030303030303030303030303030303030303030303030303964663465303561633837666535363266333562633933373939636565323738653938366662363520B8A8562A423078326434373962393034666331303435626561393663323630303538313634316630643430613733666239633333633431373865336332653333376638663363643A42307863333338613666333361656539393065303233643338363264333330326166656630306631303235336565663039343533383232373261313139316364633262400212A0020A2A30784141323435463361383138653039613833656234313331356132616339633036626635376163394112423078376632366238336666393665316632623661363832663133333835326636373938613039633436356461393539323134363063656662333834373430323439381A20000000000000000000000000000000000000000000000000000000000000000120B8A8562A423078326434373962393034666331303435626561393663323630303538313634316630643430613733666239633333633431373865336332653333376638663363643A4230786333333861366633336165653939306530323364333836326433333032616665663030663130323533656566303934353338323237326131313931636463326240031286030A2A30784141323435463361383138653039613833656234313331356132616339633036626635376163394112423078386265303037396335333136353931343133343463643166643061346632383431393439376639373232613364616166653362343138366636623634353765301242307830303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303031124230783030303030303030303030303030303030303030303030306535346535316137613438613962343634636164383233636438346436356133346365626461626420B8A8562A423078326434373962393034666331303435626561393663323630303538313634316630643430613733666239633333633431373865336332653333376638663363643A4230786333333861366633336165653939306530323364333836326433333032616665663030663130323533656566303934353338323237326131313931636463326240041286030A2A30784141323435463361383138653039613833656234313331356132616339633036626635376163394112423078386265303037396335333136353931343133343463643166643061346632383431393439376639373232613364616166653362343138366636623634353765301242307830303030303030303030303030303030303030303030303065353465353161376134386139623436346361643832336364383464363561333463656264616264124230783030303030303030303030303030303030303030303030303964663465303561633837666535363266333562633933373939636565323738653938366662363520B8A8562A423078326434373962393034666331303435626561393663323630303538313634316630643430613733666239633333633431373865336332653333376638663363643A42307863333338613666333361656539393065303233643338363264333330326166656630306631303235336565663039343533383232373261313139316364633262400512E0020A2A30786535346535316137613438413942343634434164383233636438344436354133346345624461426412423078313162363030343366313863303965323165646234366263613936643036386131393565316234303637613263663133633562316538306633343463306530361A60000000000000000000000000851A03D80C1610A7CDAE6F5E09AA970E27987FCE0000000000000000000000009DF4E05AC87FE562F35BC93799CEE278E986FB65000000000000000000000000AA245F3A818E09A83EB41315A2AC9C06BF57AC9A20B8A8562A423078326434373962393034666331303435626561393663323630303538313634316630643430613733666239633333633431373865336332653333376638663363643A4230786333333861366633336165653939306530323364333836326433333032616665663030663130323533656566303934353338323237326131313931636463326240061A20000000000000000000000000AA245F3A818E09A83EB41315A2AC9C06BF57AC9A28EB8E3E" | ||
bytesData := common.Hex2Bytes(hex) | ||
resp := &evmtypes.MsgEthereumTxResponse{} | ||
err := proto.Unmarshal(bytesData, resp) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
//revertErr := evmtypes.NewExecErrorWithReason(resp.Ret) | ||
//t.Log(revertErr) | ||
} | ||
|
||
func TestClient(t *testing.T) { | ||
|
||
//nodeURI := "tcp://localhost:26657" | ||
//grpcAddr := "localhost:9090" | ||
//chainID := "wenchangchain" | ||
nodeURI := "tcp://192.168.0.160:26657" | ||
grpcAddr := "192.168.0.160:9090" | ||
chainID := "wenchangchain-qa" | ||
|
||
bech32AddressPrefix := sdktypes.AddrPrefixCfg{ | ||
AccountAddr: "iaa", | ||
ValidatorAddr: "iva", | ||
ConsensusAddr: "ica", | ||
AccountPub: "iap", | ||
ValidatorPub: "ivp", | ||
ConsensusPub: "icp", | ||
} | ||
options := []sdktypes.Option{ | ||
sdktypes.KeyDAOOption(store.NewMemory(nil)), | ||
sdktypes.TimeoutOption(10), | ||
sdktypes.KeyManagerOption(crypto.NewKeyManager()), | ||
sdktypes.Bech32AddressPrefixOption(&bech32AddressPrefix), | ||
sdktypes.BIP44PathOption(""), | ||
} | ||
cfg, err := types.NewClientConfig(nodeURI, grpcAddr, chainID, options...) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
sdkClient := sdk.NewClient(cfg) | ||
|
||
cli := NewClient(sdkClient.BaseClient, sdkClient.EncodingConfig().TxConfig) | ||
cli.RegisterInterfaceTypes(sdkClient.EncodingConfig().InterfaceRegistry) | ||
|
||
resp1, err := sdkClient.QueryTx("51A728BAEA19FE27DC0F221B0F04C2A75D55C2D723F30FA67391AEDBF65F8049") | ||
if err != nil { | ||
panic(err) | ||
} | ||
txResponse, err := evmtypes.DecodeTxResponse(resp1.Result.Data) | ||
if err != nil { | ||
return | ||
} | ||
|
||
//if txResponse.Ret == nil { | ||
// fmt.Println("no err") | ||
// return | ||
//} | ||
|
||
revetErr := evmtypes.NewExecErrorWithReason(txResponse.Ret) | ||
fmt.Println(revetErr.ErrorData()) | ||
fmt.Println(revetErr.ErrorCode()) | ||
fmt.Println(revetErr.Error()) | ||
if err != nil { | ||
return | ||
} | ||
t.Log(revetErr) | ||
|
||
return | ||
|
||
txData := "0xf901470801831e8480941a6640c32b7e6413e839e9dfdb53970ee809b7fb80b8e4990711900000000000000000000000005892e7eeaea5ba624f5ba2900dbab8d2ea36d62b000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000001a687474703a2f2f6578616d706c652e636f6d2f746f6b656e2f35000000000000000000000000000000000000000000000000000000000000000000000000000974657374686173683600000000000000000000000000000000000000000000008209b2a050e1d159818efbae1c536b2c866920ac3c8c3720b9194b02c5ecea7717f85d2da05eabeb96aad81f432e1d7d3f84e6d38ce939e7a2d1f0bee3af2f20f507c91b96" | ||
feePayer := "0x4579DB44FD3A6F645194058914E0A8D5E8F20DB8" | ||
evmDenom := "ugas" | ||
rawTx, err := cli.BuildEvmTx(txData, feePayer, evmDenom) | ||
if err != nil { | ||
t.Log(err) | ||
return | ||
} | ||
priv := "-----BEGIN TENDERMINT PRIVATE KEY-----\nkdf: bcrypt\nsalt: 7FDD1E16A62E8B6AF914ECADCFF815FD\ntype: eth_secp256k1\n\nDHoFvjH6+FNcAj8be7oGXnpfQWlSnPG9o/yLezuDmnQWtkPcTqaAfizPG18PU3hq\nYWWxhh1a+/MNxF9u85h3Tv3vq/a7EebOsBf3AXI=\n=PI4S\n-----END TENDERMINT PRIVATE KEY-----" | ||
sdkClient.Key.Import("test01", "12345678", priv) | ||
resp, err := cli.BroadcastTxSync(context.Background(), rawTx) | ||
if err != nil { | ||
t.Log(err) | ||
return | ||
} | ||
t.Log(resp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package ethermint | ||
|
||
type IClient interface { | ||
BuildEvmTx(hexData string, feePayerAddr string, evmDemon string) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package types | ||
|
||
import ( | ||
"bytes" | ||
"math" | ||
|
||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
// IsEmptyHash returns true if the hash corresponds to an empty ethereum hex hash. | ||
func IsEmptyHash(hash string) bool { | ||
return bytes.Equal(common.HexToHash(hash).Bytes(), common.Hash{}.Bytes()) | ||
} | ||
|
||
// IsZeroAddress returns true if the address corresponds to an empty ethereum hex address. | ||
func IsZeroAddress(address string) bool { | ||
return bytes.Equal(common.HexToAddress(address).Bytes(), common.Address{}.Bytes()) | ||
} | ||
|
||
// ValidateAddress returns an error if the provided string is either not a hex formatted string address | ||
func ValidateAddress(address string) error { | ||
if !common.IsHexAddress(address) { | ||
return sdkerrors.Wrapf( | ||
sdkerrors.ErrInvalidAddress, "address '%s' is not a valid ethereum hex address", | ||
address, | ||
) | ||
} | ||
return nil | ||
} | ||
|
||
// SafeInt64 checks for overflows while casting a uint64 to int64 value. | ||
func SafeInt64(value uint64) (int64, error) { | ||
if value > uint64(math.MaxInt64) { | ||
return 0, sdkerrors.Wrapf(sdkerrors.ErrInvalidHeight, "uint64 value %v cannot exceed %v", value, int64(math.MaxInt64)) | ||
} | ||
|
||
return int64(value), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package types | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/common" | ||
ethtypes "github.com/ethereum/go-ethereum/core/types" | ||
) | ||
|
||
// AccessList is an EIP-2930 access list that represents the slice of | ||
// the protobuf AccessTuples. | ||
type AccessList []AccessTuple | ||
|
||
// NewAccessList creates a new protobuf-compatible AccessList from an ethereum | ||
// core AccessList type | ||
func NewAccessList(ethAccessList *ethtypes.AccessList) AccessList { | ||
if ethAccessList == nil { | ||
return nil | ||
} | ||
|
||
al := AccessList{} | ||
for _, tuple := range *ethAccessList { | ||
storageKeys := make([]string, len(tuple.StorageKeys)) | ||
|
||
for i := range tuple.StorageKeys { | ||
storageKeys[i] = tuple.StorageKeys[i].String() | ||
} | ||
|
||
al = append(al, AccessTuple{ | ||
Address: tuple.Address.String(), | ||
StorageKeys: storageKeys, | ||
}) | ||
} | ||
|
||
return al | ||
} | ||
|
||
// ToEthAccessList is an utility function to convert the protobuf compatible | ||
// AccessList to eth core AccessList from go-ethereum | ||
func (al AccessList) ToEthAccessList() *ethtypes.AccessList { | ||
var ethAccessList ethtypes.AccessList | ||
|
||
for _, tuple := range al { | ||
storageKeys := make([]common.Hash, len(tuple.StorageKeys)) | ||
|
||
for i := range tuple.StorageKeys { | ||
storageKeys[i] = common.HexToHash(tuple.StorageKeys[i]) | ||
} | ||
|
||
ethAccessList = append(ethAccessList, ethtypes.AccessTuple{ | ||
Address: common.HexToAddress(tuple.Address), | ||
StorageKeys: storageKeys, | ||
}) | ||
} | ||
|
||
return ðAccessList | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
remove unused code