Skip to content

Commit

Permalink
add comments for decode functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tj327 committed Dec 20, 2023
1 parent 7132c5f commit d7c8190
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
3 changes: 1 addition & 2 deletions config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ const (
DefaultKiraValAddrPrefix = "kiravaloper"
DefaultKiraDenom = "ukex"

// TODO: change endpoint to api/kira/evm
MetamaskEndpoint = "/api/k/evm"
MetamaskEndpoint = "api/kira/evm"
RegisterAddrEndpoint = "/api/kira/evm/register_address/{eth_addr}{cosmos_addr}"

QueryDashboard = "/api/dashboard"
Expand Down
26 changes: 26 additions & 0 deletions gateway/kira/metamask/cosmostxsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,17 @@ const (

var grpcConn *grpc.ClientConn

// decode 256bit param like bool, uint, hex-typed address etc
func Decode256Bit(data *[]byte, params *[][]byte) {
*params = append(*params, (*data)[:32])
*data = (*data)[32:]
}

// decode string-typed param
// structure:
// * offset - offset of the string in the data : 32byte
// * length - length of the string : 32byte
// * content - content of the string : (length/32+1)*32byte
func DecodeString(data *[]byte, params *[][]byte) {
// offset := data[:32] // string value offset
*data = (*data)[32:]
Expand All @@ -109,6 +115,13 @@ func DecodeString(data *[]byte, params *[][]byte) {
*data = (*data)[(length/32+1)*32:]
}

// decode string-typed params - if string-typed params are consecutive, offsets are placed on top
// and length, contents are placed in order
// structure:
// * offsets - offsets of the strings in the data : length*32byte
// * array of below data
// ** length - length of the string : 32byte
// ** content - content of the string : (length/32+1)*32byte
func DecodeStrings(data *[]byte, params *[][]byte, paramLen int) {
// remove offset of each string
*data = (*data)[32*paramLen:]
Expand All @@ -121,6 +134,13 @@ func DecodeStrings(data *[]byte, params *[][]byte, paramLen int) {
}
}

// decode string-array-typed param
// structure:
// * offset - offset of the strings in the data : 32byte
// * offsets - offsets of the string in the data : length*32byte
// * array of below data
// ** length - length of the string : 32byte
// ** content - content of the string : (length/32+1)*32byte
func DecodeStringArray(data *[]byte, params *[][]byte) {
// offset := data[:32] // string value offset
*data = (*data)[32:]
Expand All @@ -140,6 +160,12 @@ func DecodeStringArray(data *[]byte, params *[][]byte) {
}
}

// decode hex-array-typed param
// structure:
// * offset - offset of the hex-array in the data : 32byte
// * length - length of the hex : 32byte
// * array of below data
// ** content - content of the hex : 32byte
func DecodeHexArray(data *[]byte, params *[][]byte) {
// offset := data[:32] // string value offset
*data = (*data)[32:]
Expand Down
1 change: 0 additions & 1 deletion gateway/kira/metamask/metamask.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ func MetamaskRequestHandler(gwCosmosmux *runtime.ServeMux, rpcAddr string) http.
return
}

// TODO: check after token sending
result = fmt.Sprintf("0x%x", sequence)
case "eth_sendTransaction":
// var params EthSendTransaction
Expand Down

0 comments on commit d7c8190

Please sign in to comment.