Skip to content
This repository was archived by the owner on Aug 14, 2025. It is now read-only.
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
120 changes: 120 additions & 0 deletions common/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
tmjson "github.com/cometbft/cometbft/libs/json"
tmTypes "github.com/cometbft/cometbft/rpc/core/types"
tmJsonRPCTypes "github.com/cometbft/cometbft/rpc/jsonrpc/types"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
)
Expand Down Expand Up @@ -125,6 +126,62 @@ func GetAccountBalances(gwCosmosmux *runtime.ServeMux, r *http.Request, bech32ad
return result.Balances
}

type DappSession struct {
Leader string `protobuf:"bytes,1,opt,name=leader,proto3" json:"leader,omitempty"`
Start string `protobuf:"varint,2,opt,name=start,proto3" json:"start,omitempty"`
StatusHash string `protobuf:"bytes,3,opt,name=status_hash,json=statusHash,proto3" json:"statusHash,omitempty"`
Status string `protobuf:"varint,4,opt,name=status,proto3,enum=kira.layer2.SessionStatus" json:"status,omitempty"`
Gateway string `protobuf:"bytes,5,opt,name=gateway,proto3" json:"gateway,omitempty"`
OnchainMessages []*codectypes.Any `protobuf:"bytes,6,rep,name=onchain_messages,json=onchainMessages,proto3" json:"onchainMessages,omitempty"`
}

type ExecutionRegistrar struct {
DappName string `protobuf:"bytes,1,opt,name=dapp_name,json=dappName,proto3" json:"dappName,omitempty"`
PrevSession *DappSession `protobuf:"bytes,2,opt,name=prev_session,json=prevSession,proto3" json:"prevSession,omitempty"`
CurrSession *DappSession `protobuf:"bytes,3,opt,name=curr_session,json=currSession,proto3" json:"currSession,omitempty"`
NextSession *DappSession `protobuf:"bytes,4,opt,name=next_session,json=nextSession,proto3" json:"nextSession,omitempty"`
}

type DappOperator struct {
DappName string `protobuf:"bytes,1,opt,name=dapp_name,json=dappName,proto3" json:"dappName,omitempty"`
Operator string `protobuf:"bytes,2,opt,name=operator,proto3" json:"operator,omitempty"`
Executor bool `protobuf:"varint,3,opt,name=executor,proto3" json:"executor,omitempty"`
Verifier bool `protobuf:"varint,4,opt,name=verifier,proto3" json:"verifier,omitempty"`
Interx string `protobuf:"bytes,5,opt,name=interx,proto3" json:"interx,omitempty"`
Status string `protobuf:"varint,6,opt,name=status,proto3,enum=kira.layer2.OperatorStatus" json:"status,omitempty"`
Rank string `protobuf:"varint,7,opt,name=rank,proto3" json:"rank,omitempty"`
Streak string `protobuf:"varint,8,opt,name=streak,proto3" json:"streak,omitempty"`
Mischance string `protobuf:"varint,9,opt,name=mischance,proto3" json:"mischance,omitempty"`
VerifiedSessions string `protobuf:"varint,10,opt,name=verified_sessions,json=verifiedSessions,proto3" json:"verifiedSessions,omitempty"`
MissedSessions string `protobuf:"varint,11,opt,name=missed_sessions,json=missedSessions,proto3" json:"missedSessions,omitempty"`
BondedLpAmount string `protobuf:"bytes,12,opt,name=bonded_lp_amount,json=bondedLpAmount,proto3" json:"bondedLpAmount"`
}

type QueryExecutionRegistrarResponse struct {
Dapp interface{} `protobuf:"bytes,1,opt,name=dapp,proto3" json:"dapp,omitempty"`
ExecutionRegistrar *ExecutionRegistrar `json:"executionRegistrar,omitempty"`
Operators []DappOperator `protobuf:"bytes,3,rep,name=operators,proto3" json:"operators"`
}

func GetExecutionRegistrar(gwCosmosmux *runtime.ServeMux, r *http.Request, appName string) QueryExecutionRegistrarResponse {
r.URL.Path = fmt.Sprintf("/kira/layer2/execution_registrar/%s", appName)
r.URL.RawQuery = ""
r.Method = "GET"

recorder := httptest.NewRecorder()
gwCosmosmux.ServeHTTP(recorder, r)
resp := recorder.Result()

result := QueryExecutionRegistrarResponse{}

err := json.NewDecoder(resp.Body).Decode(&result)
if err != nil {
GetLogger().Error("[grpc-call] Unable to decode response: ", err)
}

return result
}

// GetAccountNumberSequence is a function to get AccountNumber and Sequence
func GetAccountNumberSequence(gwCosmosmux *runtime.ServeMux, r *http.Request, bech32addr string) (uint64, uint64) {
_, err := sdk.AccAddressFromBech32(bech32addr)
Expand Down Expand Up @@ -163,6 +220,44 @@ func GetAccountNumberSequence(gwCosmosmux *runtime.ServeMux, r *http.Request, be
return uint64(accountNumber), uint64(sequence)
}

func BroadcastTransactionSync(rpcAddr string, txBytes []byte) (string, error) {
endpoint := fmt.Sprintf("%s/broadcast_tx_sync?tx=0x%X", rpcAddr, txBytes)
GetLogger().Info("[rpc-call] Entering rpc call: ", endpoint)

resp, err := http.Get(endpoint)
if err != nil {
GetLogger().Error("[rpc-call] Unable to connect to ", endpoint)
return "", err
}
defer resp.Body.Close()

type RPCTempResponse struct {
Jsonrpc string `json:"jsonrpc"`
ID int `json:"id"`
Result struct {
Height string `json:"height"`
Hash string `json:"hash"`
} `json:"result,omitempty"`
Error struct {
Message string `json:"message"`
} `json:"error,omitempty"`
}

result := new(RPCTempResponse)
err = json.NewDecoder(resp.Body).Decode(result)
if err != nil {
GetLogger().Error("[rpc-call] Unable to decode response: ", err)
return "", err
}

if resp.StatusCode != http.StatusOK {
GetLogger().Error("[rpc-call] Unable to broadcast transaction: ", result.Error.Message)
return "", errors.New(result.Error.Message)
}

return result.Result.Hash, nil
}

// BroadcastTransaction is a function to post transaction, returns txHash
func BroadcastTransaction(rpcAddr string, txBytes []byte) (string, error) {
endpoint := fmt.Sprintf("%s/broadcast_tx_async?tx=0x%X", rpcAddr, txBytes)
Expand Down Expand Up @@ -418,6 +513,31 @@ func GetKiraStatus(rpcAddr string) *types.KiraStatus {
return nil
}

// TODO: get abr with appname param
func GetABR(rpcAddr string, appName string) (uint64, error) {
success, _, _ := MakeTendermintRPCRequest(rpcAddr, "/layer2/abr/"+appName, "")

if success != nil {
result := types.AppBridgeRegistrar{}

byteData, err := json.Marshal(success)
if err != nil {
GetLogger().Error("[kira-abr] Invalid response format", err)
return 0, err
}

err = json.Unmarshal(byteData, &result)
if err != nil {
GetLogger().Error("[kira-abr] Invalid response format", err)
return 0, err
}

return result.Abr, nil
}

return 0, errors.New("[kira-abr] not found abr")
}

func GetInterxStatus(interxAddr string) *types.InterxStatus {
success, _, _ := MakeGetRequest(interxAddr, "/api/status", "")

Expand Down
2 changes: 2 additions & 0 deletions common/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,5 @@ func IsCacheExpired(result types.InterxResponse) bool {

return isBlockExpire || isTimestampExpire
}

var Layer2Status map[string]string
6 changes: 5 additions & 1 deletion config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package config

const (
InterxVersion = "v0.4.48"
SekaiVersion = "v0.3.42"
SekaiVersion = "v0.4.0"
CosmosVersion = "v0.47.6"

QueryDashboard = "/api/dashboard"
Expand Down Expand Up @@ -76,7 +76,10 @@ const (
QueryAddrBook = "/api/addrbook"
QueryNetInfo = "/api/net_info"

QueryLayer2Status = "/api/layer2/{appName}/status"

Download = "/download"
AppDownload = "/app/download"
DataReferenceRegistry = "DRR"
DefaultInterxPort = "11000"

Expand Down Expand Up @@ -182,3 +185,4 @@ var MsgTypes = map[string]string{
}
var SupportedEVMChains = [1]string{"goerli"}
var SupportedBitcoinChains = [1]string{"testnet"}
var SupportedLayer2Apps = [1]string{"l2chess"}
51 changes: 33 additions & 18 deletions config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,10 @@ func defaultConfig() InterxConfigFromFile {
configFromFile.RPC = "http://0.0.0.0:26657"
configFromFile.PORT = "11000"

configFromFile.Node.NodeType = "seed"
configFromFile.Node.SentryNodeID = ""
configFromFile.Node.SnapshotNodeID = ""
configFromFile.Node.ValidatorNodeID = ""
configFromFile.Node.SeedNodeID = ""
configFromFile.NodeType = "validator"

entropy, _ := bip39.NewEntropy(256)
configFromFile.MnemonicFile, _ = bip39.NewMnemonic(entropy)
configFromFile.Mnemonic, _ = bip39.NewMnemonic(entropy)

configFromFile.AddrBooks = "addrbook.json"
configFromFile.NodeKey = "node_key.json"
Expand All @@ -140,7 +136,7 @@ func defaultConfig() InterxConfigFromFile {
configFromFile.Cache.CachingDuration = 5
configFromFile.Cache.DownloadFileSizeLimitation = "10MB"

configFromFile.Faucet.MnemonicFile = configFromFile.MnemonicFile
configFromFile.Faucet.Mnemonic = configFromFile.Mnemonic

configFromFile.Faucet.FaucetAmounts = make(map[string]string)
configFromFile.Faucet.FaucetAmounts["stake"] = "100000"
Expand All @@ -156,6 +152,13 @@ func defaultConfig() InterxConfigFromFile {
configFromFile.Faucet.FeeAmounts["ukex"] = "1000ukex"
configFromFile.Faucet.TimeLimit = 20

configFromFile.AppSetting.AppMock = false
configFromFile.AppSetting.AppMode = 0
configFromFile.AppSetting.AppName = "app_name"
entropy, _ = bip39.NewEntropy(256)
mnemonicFile, _ := bip39.NewMnemonic(entropy)
configFromFile.AppSetting.AppMnemonic = mnemonicFile

configFromFile.Evm = make(map[string]EVMConfig)
for _, item := range SupportedEVMChains {
evmConfig := EVMConfig{}
Expand Down Expand Up @@ -197,6 +200,17 @@ func defaultConfig() InterxConfigFromFile {
configFromFile.Bitcoin[item] = bitcoinConfig
}

configFromFile.CachingBin = false

configFromFile.Layer2 = make(map[string]Layer2Config)
for _, item := range SupportedLayer2Apps {
layer2Config := Layer2Config{
RPC: "http://127.0.0.1:9000",
Fee: "300ukex",
}
configFromFile.Layer2[item] = layer2Config
}

return configFromFile
}

Expand All @@ -207,10 +221,6 @@ func InitConfig(
grpc string,
rpc string,
nodeType string,
sentryNodeId string,
snapshotNodeId string,
validatorNodeId string,
seedNodeId string,
port string,
signingMnemonic string,
syncStatus int64,
Expand All @@ -232,6 +242,10 @@ func InitConfig(
nodeDiscoveryTimeout string,
nodeKey string,
snapshotInterval uint64,
appMode int,
appMock bool,
appName string,
appMnemonic string,
) {
configFromFile := defaultConfig()

Expand All @@ -240,13 +254,9 @@ func InitConfig(
configFromFile.RPC = rpc
configFromFile.PORT = port

configFromFile.Node.NodeType = nodeType
configFromFile.Node.SentryNodeID = sentryNodeId
configFromFile.Node.SnapshotNodeID = snapshotNodeId
configFromFile.Node.ValidatorNodeID = validatorNodeId
configFromFile.Node.SeedNodeID = seedNodeId
configFromFile.NodeType = nodeType

configFromFile.MnemonicFile = signingMnemonic
configFromFile.Mnemonic = signingMnemonic

configFromFile.AddrBooks = addrBooks
configFromFile.NodeKey = nodeKey
Expand All @@ -265,9 +275,14 @@ func InitConfig(
configFromFile.Cache.CachingDuration = cachingDuration
configFromFile.Cache.DownloadFileSizeLimitation = maxDownloadSize

configFromFile.Faucet.MnemonicFile = faucetMnemonic
configFromFile.Faucet.Mnemonic = faucetMnemonic
configFromFile.Faucet.TimeLimit = faucetTimeLimit

configFromFile.AppSetting.AppMock = appMock
configFromFile.AppSetting.AppMode = appMode
configFromFile.AppSetting.AppName = appName
configFromFile.AppSetting.AppMnemonic = appMnemonic

configFromFile.Faucet.FaucetAmounts = make(map[string]string)
for _, amount := range strings.Split(faucetAmounts, ",") {
coin, err := sdk.ParseCoinNormalized(amount)
Expand Down
Loading