Skip to content

Commit

Permalink
Merge pull request #7 from bandprotocol/tss-support-request-feeds-sig…
Browse files Browse the repository at this point in the history
…nature

[TSS] Implement to support request feeds signature
  • Loading branch information
nkitlabs authored Jun 6, 2024
2 parents 95a4b53 + ab69a60 commit 9a612c1
Show file tree
Hide file tree
Showing 22 changed files with 584 additions and 276 deletions.
3 changes: 1 addition & 2 deletions client/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package client

import (
oracletypes "github.com/bandprotocol/chain/v2/x/oracle/types"
ctypes "github.com/cometbft/cometbft/rpc/core/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
Expand All @@ -16,7 +15,7 @@ type Client interface {
GetBlockResult(height int64) (*ctypes.ResultBlockResults, error)
QueryRequestFailureReason(id uint64) (string, error)
GetBalance(account sdk.AccAddress) (uint64, error)
SendRequest(msg *oracletypes.MsgRequestData, gasPrice float64, key keyring.Record) (*sdk.TxResponse, error)
SendRequest(msg sdk.Msg, gasPrice float64, key keyring.Record) (*sdk.TxResponse, error)
GetRequestProofByID(reqID uint64) ([]byte, error)
Subscribe(name, query string) (*SubscriptionInfo, error)
Unsubscribe(name string) error
Expand Down
18 changes: 2 additions & 16 deletions client/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client
import (
"context"
"fmt"
"strconv"
"time"

band "github.com/bandprotocol/chain/v2/app"
Expand Down Expand Up @@ -57,7 +56,7 @@ func createTxFactory(chainID, gasPrice string, keyring keyring.Keyring) tx.Facto
return tx.Factory{}.
WithChainID(chainID).
WithTxConfig(band.MakeEncodingConfig().TxConfig).
WithGasAdjustment(1.1).
WithGasAdjustment(1.2).
WithGasPrices(gasPrice).
WithKeybase(keyring).
WithSignMode(signing.SignMode_SIGN_MODE_DIRECT)
Expand Down Expand Up @@ -86,20 +85,6 @@ func estimateGas(clientCtx client.Context, txf tx.Factory, msgs ...sdk.Msg) (uin
return gas, err
}

func GetRequestID(events []sdk.StringEvent) (uint64, error) {
for _, event := range events {
if event.Type == oracletypes.EventTypeRequest {
rid, err := strconv.ParseUint(event.Attributes[0].Value, 10, 64)
if err != nil {
return 0, err
}

return rid, nil
}
}
return 0, fmt.Errorf("cannot find request id")
}

func convertSigningResultToSigningInfo(res *tsstypes.SigningResult) SigningInfo {
if res == nil {
return SigningInfo{}
Expand All @@ -111,6 +96,7 @@ func convertSigningResultToSigningInfo(res *tsstypes.SigningResult) SigningInfo
}

return SigningInfo{
Message: res.Signing.Message,
PubKey: res.Signing.GroupPubKey,
PubNonce: res.Signing.GroupPubNonce,
Status: res.Signing.Status,
Expand Down
15 changes: 7 additions & 8 deletions client/mock/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func (c RPC) GetBalance(_ sdk.AccAddress) (uint64, error) {
return 0, nil
}

func (c RPC) SendRequest(msg *oracletypes.MsgRequestData, gasPrice float64, key keyring.Record) (*sdk.TxResponse, error) {
func (c RPC) SendRequest(msg sdk.Msg, gasPrice float64, key keyring.Record) (*sdk.TxResponse, error) {
// Get account to get nonce of sender first
addr, err := key.GetAddress()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func (s SigningResult) IsReady() bool {

// SigningInfo contains signing information.
type SigningInfo struct {
Message []byte
EVMSignature tsstypes.EVMSignature
Status tsstypes.SigningStatus
PubKey []byte
Expand Down
55 changes: 55 additions & 0 deletions examples/requester/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package main

import (
"os"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/spf13/viper"
)

type ChainConfig struct {
ChainID string `yaml:"chain_id" mapstructure:"chain_id"`
RPC string `yaml:"rpc" mapstructure:"rpc"`
Fee string `yaml:"fee" mapstructure:"fee"`
Timeout time.Duration `yaml:"timeout" mapstructure:"timeout"`
}

type RequestConfig struct {
OracleScriptID int `yaml:"oracle_script_id" mapstructure:"oracle_script_id"`
Calldata string `yaml:"calldata" mapstructure:"calldata"`
Mnemonic string `yaml:"mnemonic" mapstructure:"mnemonic"`
}

type Config struct {
Chain ChainConfig `yaml:"chain" mapstructure:"chain"`
Request RequestConfig `yaml:"request" mapstructure:"request"`
LogLevel string `yaml:"log_level" mapstructure:"log_level"`
SDK *sdk.Config
}

func GetConfig(name string) (Config, error) {
viper.SetConfigType("yaml")
viper.SetConfigName(name)
viper.AddConfigPath("./requester/configs")

if err := viper.ReadInConfig(); err != nil {
return Config{}, err
}

var config Config
if err := viper.Unmarshal(&config); err != nil {
return Config{}, err
}

config.SDK = sdk.GetConfig()

return config, nil
}

func GetEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
}
Loading

0 comments on commit 9a612c1

Please sign in to comment.