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

fix contract name to evm address bug when contract name length is 16 #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion account/address_trans.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ func evmAddressToContractName(evmAddr crypto.Address) (string, error) {
contractNameWithPrefix := evmAddr.Bytes()
contractNameStrWithPrefix := string(contractNameWithPrefix)
prefixIndex := strings.LastIndex(contractNameStrWithPrefix, evmAddressFiller)

if prefixIndex == -1 {
return contractNameStrWithPrefix[4:], nil
}
return contractNameStrWithPrefix[prefixIndex+1:], nil
}

Expand Down
5 changes: 5 additions & 0 deletions account/address_trans_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func TestTrans(t *testing.T) {
Type: "contract-name",
EVMAddress: "313131312D2D2D73746F72616765646174613131",
},
{
XchainAddress: "mike_test_sol_31",
Type: "contract-name",
EVMAddress: "313131316D696B655F746573745F736F6C5F3331",
},
}

for _, c := range cases {
Expand Down