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

feature/kip-87 -> release/v0.4.42 #204

Closed
wants to merge 50 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
36abaec
implement metamask send & eip712 signed transactions
tj327 Dec 20, 2023
7132c5f
upgrade interx version to v0.4.42
tj327 Dec 20, 2023
d7c8190
add comments for decode functions
tj327 Dec 20, 2023
b3f5d6b
update endpoint&fix decodeparams issue
tj327 Dec 21, 2023
f84baea
add verification of eip-712 signed transaction
tj327 Jan 5, 2024
a0e7a32
check validation of eip-712 signed tx
tj327 Jan 8, 2024
17570cf
Merge pull request #207 from KiraCore/release/v0.4.42
asmodat Jan 8, 2024
91464ea
finish validation of eip712-signed tx
tj327 Jan 9, 2024
d26bf95
fix unsupported type while unmarshalling
tj327 Jan 10, 2024
d052252
fix validation issues
tj327 Jan 11, 2024
cd4b614
make sleep interval for snapshot checksum
tj327 Jan 11, 2024
294dfc6
version update
tj327 Jan 11, 2024
d6b12b8
Merge pull request #209 from KiraCore/bugfix/performance
kmlbgn Jan 11, 2024
3448c1c
Merge pull request #210 from KiraCore/release/v0.4.43
asmodat Jan 12, 2024
4b0da1f
Merge branch 'master' into feature/kip-87
tj327 Jan 12, 2024
487eae3
pagination for tokenalias
tj327 Jan 25, 2024
0ca7eb6
add custom pagination for balance query
tj327 Jan 30, 2024
af21064
set default limit to 100 for custom pagination
tj327 Jan 30, 2024
2f99458
add derived filter and release version
tj327 Feb 1, 2024
99791e0
fix integration test
tj327 Feb 1, 2024
a9ba7dc
Merge pull request #213 from KiraCore/bugfix/pagination
tj327 Feb 1, 2024
ad319c8
pending work for geo node discovery
tj327 Feb 15, 2024
380f336
update pagination fields to string
tj327 Feb 15, 2024
af36e47
Merge pull request #217 from KiraCore/bugfix/pagination_fields_string
tj327 Feb 15, 2024
aeba211
Merge pull request #214 from KiraCore/release/v0.4.44
asmodat Feb 19, 2024
ea577cd
add release version
tj327 Feb 20, 2024
951d3fe
Merge pull request #219 from KiraCore/feature/pagination_query_release
MrLutik Feb 20, 2024
9e83167
update node discovery
tj327 Feb 22, 2024
7afb185
Merge branch 'master' of github.com:KiraCore/interx into feature/geo_…
tj327 Feb 22, 2024
6db9cea
Merge pull request #220 from KiraCore/release/v0.4.45
MrLutik Feb 22, 2024
8188d1c
Merge branch 'master' of github.com:KiraCore/interx into feature/geo_…
tj327 Feb 23, 2024
b551939
release v0.4.46
tj327 Feb 23, 2024
90897fb
Merge pull request #222 from KiraCore/feature/geo_fields
kmlbgn Feb 26, 2024
62abe5f
Merge pull request #223 from KiraCore/release/v0.4.46
MrLutik Mar 2, 2024
2dbf8b5
feat(cook_hook): Add webhook to sekin
MrLutik Mar 3, 2024
b72f0b1
feat(cook_hook): Preapare for release
MrLutik Mar 3, 2024
b38cacd
feat(cook_hook) Fix idention
MrLutik Mar 4, 2024
cf3625d
feat(cook_hook): Bump interx version
MrLutik Mar 4, 2024
05ad1a2
Merge branch 'release/v0.4.47' into feature/cook_hook
MrLutik Mar 4, 2024
a55c8bf
Merge pull request #225 from KiraCore/feature/cook_hook
MrLutik Mar 4, 2024
f8eb2ab
Merge pull request #226 from KiraCore/release/v0.4.47
MrLutik Mar 4, 2024
8d849f9
peers number count fix
tj327 Mar 6, 2024
0e022fb
feat(cook_hook) Refactor
MrLutik Mar 7, 2024
2534e75
Update RELEASE
MrLutik Mar 7, 2024
68b249c
Merge pull request #229 from KiraCore/feature/cook_hook
MrLutik Mar 7, 2024
8abe867
Merge pull request #230 from KiraCore/release/v0.4.48
MrLutik Mar 7, 2024
b69ef2d
metamask tx submission update
tj327 May 8, 2024
57e3dd7
revert sekai replace in go.mod
tj327 May 8, 2024
a21de55
Merge branch 'master' of github.com:KiraCore/interx into feature/kip-87
tj327 May 23, 2024
6f027ac
release
tj327 May 23, 2024
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: 2 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Features:

* Implement QueryUndelegations endpoint
* Bump sekai version to v0.3.38
* Implement KIP-87 : broadcast metamask coin send transaction to sekai
* Implement KIP-87 : broadcast eip-712 signed transaction to sekai
10 changes: 9 additions & 1 deletion config/constants.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
package config

const (
InterxVersion = "v0.4.41"
InterxVersion = "v0.4.42"
SekaiVersion = "v0.3.38"
CosmosVersion = "v0.47.5"

DefaultChainID = 8789
DefaultKiraAddrPrefix = "kira"
DefaultKiraValAddrPrefix = "kiravaloper"
DefaultKiraDenom = "ukex"

MetamaskEndpoint = "/api/kira/evm"
RegisterAddrEndpoint = "/api/kira/evm/register_address/{eth_addr}{cosmos_addr}"

QueryDashboard = "/api/dashboard"

QueryAccounts = "/api/kira/accounts/{address}"
Expand Down
2 changes: 2 additions & 0 deletions gateway/kira/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kira

import (
"github.com/KiraCore/interx/gateway/kira/metamask"
"github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
)
Expand All @@ -18,4 +19,5 @@ func RegisterRequest(router *mux.Router, gwCosmosmux *runtime.ServeMux, rpcAddr
RegisterKiraSpendingRoutes(router, gwCosmosmux, rpcAddr)
RegisterKiraUbiRoutes(router, gwCosmosmux, rpcAddr)
RegisterKiraMultiStakingRoutes(router, gwCosmosmux, rpcAddr)
metamask.RegisterKiraMetamaskRoutes(router, gwCosmosmux, rpcAddr)
}
31 changes: 31 additions & 0 deletions gateway/kira/metamask/cosmosaccountinfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package metamask

import (
"net/http"

"github.com/KiraCore/interx/common"
interxtypes "github.com/KiraCore/interx/types"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
)

func GetAccountInfo(params EthGetTransactionCount, gwCosmosmux *runtime.ServeMux, r *http.Request) (uint64, uint64, error) {
bech32Addr, err := hex2bech32(params.From, TypeKiraAddr)
if err != nil {
return 0, 0, err
}

accountNumber, sequence := common.GetAccountNumberSequence(gwCosmosmux, r, bech32Addr)

return accountNumber, sequence, nil
}

func GetBalance(params EthGetBalanceParams, gwCosmosmux *runtime.ServeMux, r *http.Request) []interxtypes.Coin {
bech32Addr, err := hex2bech32(params.From, TypeKiraAddr)
if err != nil {
return nil
}

balances := common.GetAccountBalances(gwCosmosmux, r.Clone(r.Context()), bech32Addr)

return balances
}
162 changes: 162 additions & 0 deletions gateway/kira/metamask/cosmosblockinfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
package metamask

import (
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"encoding/json"
"fmt"
"strconv"
"strings"
"time"

"github.com/KiraCore/interx/common"
types "github.com/cometbft/cometbft/proto/tendermint/types"
)

const (
BlockQueryByNumber = iota
BLockQueryByHash
)

type PartSetHeader struct {
Total uint32 `json:"total,omitempty"`
Hash []byte `json:"hash,omitempty"`
}

type BlockID struct {
Hash string `json:"hash,omitempty"`
PartSetHeader PartSetHeader `json:"part_set_header"`
}

type Consensus struct {
Block uint64 `json:"block,string,omitempty"`
App uint64 `json:"app,string,omitempty"`
}

type Header struct {
// basic block info
Version Consensus `json:"version"`
ChainID string `json:"chain_id,omitempty"`
Height int64 `json:"height,string,omitempty"`
Time time.Time `json:"time"`
// prev block info
LastBlockId types.BlockID `json:"last_block_id"`
// hashes of block data
LastCommitHash string `json:"last_commit_hash,omitempty"`
DataHash string `json:"data_hash,omitempty"`
// hashes from the app output from the prev block
ValidatorsHash string `json:"validators_hash,omitempty"`
NextValidatorsHash string `json:"next_validators_hash,omitempty"`
ConsensusHash string `json:"consensus_hash,omitempty"`
AppHash string `json:"app_hash,omitempty"`
LastResultsHash string `json:"last_results_hash,omitempty"`
// consensus info
EvidenceHash string `json:"evidence_hash,omitempty"`
// proposer_address is the original block proposer address, formatted as a Bech32 string.
// In Tendermint, this type is `bytes`, but in the SDK, we convert it to a Bech32 string
// for better UX.
ProposerAddress string `json:"proposer_address,omitempty"`
}

type Commit struct {
Height int64 `json:"height,string,omitempty"`
Round int32 `json:"round,omitempty"`
BlockID BlockID `json:"block_id"`
Signatures []types.CommitSig `json:"signatures"`
}

type Data struct {
// Txs that will be applied by state @ block.Height+1.
// NOTE: not all txs here are valid. We're just agreeing on the order first.
// This means that block.AppHash does not include these txs.
Txs []string `protobuf:"bytes,1,rep,name=txs,proto3" json:"txs,omitempty"`
}

type Block struct {
Header Header `json:"header"`
Data Data `json:"data"`
Evidence types.EvidenceList `json:"evidence"`
LastCommit Commit `json:"last_commit,omitempty"`
}

type CosmosBlockInfo struct {
BlockId BlockID `json:"block_id,omitempty"`
// Since: cosmos-sdk 0.47
SdkBlock Block `json:"block,omitempty"`
}

func GetBlockNumber(rpcAddr string) (int, error) {
sentryStatus := common.GetKiraStatus((rpcAddr))
currentHeight, err := strconv.Atoi(sentryStatus.SyncInfo.LatestBlockHeight)
return currentHeight, err
}

func GetBlockByNumberOrHash(blockParam string, rpcAddr string, queryType int) (CosmosBlockInfo, []string, interface{}) {
var responseData, blockErr interface{}
var statusCode int
if queryType == BlockQueryByNumber {
var blockNum int64
var err error
if strings.Contains(blockParam, "0x") {
blockNum, err = hex2int64(blockParam)
} else {
blockNum, err = strconv.ParseInt(blockParam, 10, 64)
}
if err != nil {
return CosmosBlockInfo{}, nil, err
}

responseData, blockErr, statusCode = queryBlockByHeight(rpcAddr, strconv.Itoa(int(blockNum)))
} else if queryType == BLockQueryByHash {
if !strings.Contains(blockParam, "0x") {
blockParam = "0x" + blockParam
}
responseData, blockErr, statusCode = queryBlockByHash(rpcAddr, blockParam)
}
if blockErr != nil {
return CosmosBlockInfo{}, nil, blockErr
}

if statusCode != 200 {
return CosmosBlockInfo{}, nil, fmt.Errorf("request faield, status code - %d", statusCode)
}

jsonData, err := json.Marshal(responseData)
if err != nil {
return CosmosBlockInfo{}, nil, err
}

response := CosmosBlockInfo{}
err = json.Unmarshal(jsonData, &response)
if err != nil {
return CosmosBlockInfo{}, nil, err
}

txhashes := []string{}
txs := response.SdkBlock.Data.Txs
for _, txStr := range txs {
txBz, err := base64.StdEncoding.DecodeString(txStr)
if err != nil {
return CosmosBlockInfo{}, nil, err
}
converted := []byte(txBz)
hasher := sha256.New()
hasher.Write(converted)
txhashes = append(txhashes, "0x"+hex.EncodeToString(hasher.Sum(nil)))
}

return response, txhashes, nil
}

func queryBlockByHeight(rpcAddr string, height string) (interface{}, interface{}, int) {
success, err, statusCode := common.MakeTendermintRPCRequest(rpcAddr, "/block", fmt.Sprintf("height=%s", height))

return success, err, statusCode
}

func queryBlockByHash(rpcAddr string, height string) (interface{}, interface{}, int) {
success, err, statusCode := common.MakeTendermintRPCRequest(rpcAddr, "/block_by_hash", fmt.Sprintf("hash=%s", height))

return success, err, statusCode
}
120 changes: 120 additions & 0 deletions gateway/kira/metamask/cosmostxinfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package metamask

import (
"encoding/json"
"fmt"
"strings"

"github.com/KiraCore/interx/common"
)

// Attribute is a struct that represents an attribute in the JSON data
type Attribute struct {
Key string `json:"key"`
Value string `json:"value"`
}

// Event is a struct that represents an event in the JSON data
type Event struct {
Type string `json:"type"`
Attributes []Attribute `json:"attributes"`
}

// Msg is a struct that represents a message in the JSON data
type LogInfo struct {
MsgIndex int `json:"msg_index"`
Events []Event `json:"events"`
}

// map[msgIndex][event_type][attribute_key]
type LogInfoForMap struct {
LogInfo map[int]map[string]map[string]string
}

type Log struct {
logForMap map[int]LogInfoForMap
logForString string
}

type TxInfo struct {
Hash string `json:"hash"`
Height string `json:"height"`
Index int `json:"index"`
TxResult struct {
Code int `json:"code"`
Data string `json:"data"`
Log string `json:"log"`
Info string `json:"info"`
GasWanted string `json:"gas_wanted"`
GasUsed string `json:"gas_used"`
Events []struct {
Type string `json:"type"`
Attributes []struct {
Key string `json:"key"`
Value string `json:"value"`
Index bool `json:"index"`
} `json:"attributes"`
} `json:"events"`
Codespace string `json:"codespace"`
} `json:"tx_result"`
Tx string `json:"tx"`
}

func GetTxInfo(txHash string, rpcAddr string) (TxInfo, Log, interface{}) {
responseData, err, statusCode := queryTxByHash(rpcAddr, txHash)
logResult := Log{}

if err != nil {
return TxInfo{}, logResult, err
}

if statusCode != 200 {
return TxInfo{}, logResult, fmt.Errorf("request faield, status code - %d", statusCode)
}

jsonData, err := json.Marshal(responseData)
if err != nil {
return TxInfo{}, logResult, err
}

response := TxInfo{}
err = json.Unmarshal(jsonData, &response)
if err != nil {
return TxInfo{}, logResult, err
}

var logInfos []LogInfo

// Unmarshal the JSON data to the msgs slice
err = json.Unmarshal([]byte(response.TxResult.Log), &logInfos)
logResult.logForString = response.TxResult.Log
if err != nil {
return response, logResult, nil
}

logInfosForMap := map[int]LogInfoForMap{}
for i, logInfo := range logInfos {
logInfosForMap[i] = LogInfoForMap{LogInfo: make(map[int]map[string]map[string]string)}
for _, event := range logInfo.Events {
if logInfosForMap[i].LogInfo[logInfo.MsgIndex] == nil {
logInfosForMap[i].LogInfo[logInfo.MsgIndex] = make(map[string]map[string]string)
}
if logInfosForMap[i].LogInfo[logInfo.MsgIndex][event.Type] == nil {
logInfosForMap[i].LogInfo[logInfo.MsgIndex][event.Type] = make(map[string]string)
}
for _, attribute := range event.Attributes {
logInfosForMap[i].LogInfo[logInfo.MsgIndex][event.Type][attribute.Key] = attribute.Value
}
}
}

logResult.logForMap = logInfosForMap
return response, logResult, nil
}

func queryTxByHash(rpcAddr string, hash string) (interface{}, interface{}, int) {
if !strings.HasPrefix(hash, "0x") {
hash = "0x" + hash
}
return common.MakeTendermintRPCRequest(rpcAddr, "/tx", fmt.Sprintf("hash=%s", hash))
}
Loading
Loading