Skip to content

Commit

Permalink
merge upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
keithsue committed Jul 9, 2024
2 parents 5b798ee + 390650a commit 334354f
Show file tree
Hide file tree
Showing 33 changed files with 3,332 additions and 337 deletions.
2 changes: 2 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
appCodec,
appKeepers.keys[btcbridgetypes.StoreKey],
appKeepers.keys[btcbridgetypes.StoreKey],
govAuthor,
appKeepers.BankKeeper,
)

Expand Down Expand Up @@ -471,6 +472,7 @@ func (appKeepers *AppKeepers) initParamsKeeper(appCodec codec.BinaryCodec, legac
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(gmmmoduletypes.ModuleName)
paramsKeeper.Subspace(yieldmoduletypes.ModuleName)
paramsKeeper.Subspace(btcbridgetypes.ModuleName)

return paramsKeeper
}
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/spf13/cast v1.5.1
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
)

require (
Expand Down Expand Up @@ -56,7 +56,6 @@ require (
github.com/confio/ics23/go v0.9.0 // indirect
github.com/containerd/containerd v1.6.8 // indirect
github.com/containerd/typeurl v1.0.2 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v0.20.1 // indirect
Expand Down Expand Up @@ -172,7 +171,7 @@ require (
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.16.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
Expand Down Expand Up @@ -221,6 +220,7 @@ require (
github.com/btcsuite/btcd/btcutil/psbt v1.1.9
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0
github.com/bufbuild/buf v1.7.0
github.com/cosmos/btcutil v1.0.5
github.com/cosmos/cosmos-proto v1.0.0-beta.4
github.com/cosmos/ics23/go v0.10.0
github.com/prometheus/client_golang v1.16.0
Expand All @@ -231,6 +231,7 @@ require (
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0
google.golang.org/protobuf v1.32.0
gopkg.in/yaml.v2 v2.4.0
lukechampine.com/uint128 v1.3.0
)

replace (
Expand Down
9 changes: 6 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1018,8 +1018,9 @@ github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5J
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
Expand All @@ -1030,8 +1031,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8=
github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY=
Expand Down Expand Up @@ -1748,6 +1749,8 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
lukechampine.com/uint128 v1.3.0 h1:cDdUVfRwDUDovz610ABgFD17nXD4/uDgVHl2sC3+sbo=
lukechampine.com/uint128 v1.3.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
nhooyr.io/websocket v1.8.6 h1:s+C3xAMLwGmlI31Nyn/eAehUlZPwfYZu2JXM621Q5/k=
nhooyr.io/websocket v1.8.6/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0=
pgregory.net/rapid v1.1.0 h1:CMa0sjHSru3puNx+J0MIAuiiEV4N0qj8/cMWGBBCsjw=
Expand Down
16 changes: 11 additions & 5 deletions local_node_dev.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/bash

KEYS=("dev0" "dev1" "dev2")
KEYS=("validator" "test" "relayer")
CHAINID="devnet"
MONIKER="Side Labs"
BINARY="$HOME/go/bin/sided"
DENOM_STR="uside,sat"
INITIAL_ACCOUNT_STR=""
DENOM_STR="uside,sat,uusdc,uusdt"
INITIAL_ACCOUNT_STR="tb1qcr8te4kr609gcawutmrza0j4xv80jy8zmfp6l0"
set -f
IFS=,
DENOMS=($DENOM_STR)
Expand Down Expand Up @@ -91,9 +91,15 @@ if [[ $overwrite == "y" || $overwrite == "Y" ]]; then
# setup relayers
RELAYER=$($BINARY keys show "${KEYS[2]}" -a --keyring-backend $KEYRING --home "$HOMEDIR")
jq --arg relayer "$RELAYER" '.app_state["btcbridge"]["params"]["authorized_relayers"][0]=$relayer' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq --arg relayer "$RELAYER" '.app_state["btcbridge"]["params"]["vaults"][0]["address"]=$relayer' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
PUKEY=$($BINARY keys show "${KEYS[2]}" --pubkeyhex --keyring-backend $KEYRING --home "$HOMEDIR")
# setup vaults
VAULT1=$($BINARY keys show "${KEYS[1]}" -a --keyring-backend $KEYRING --home "$HOMEDIR")
jq --arg vault1 "$VAULT1" '.app_state["btcbridge"]["params"]["vaults"][0]["address"]=$vault1' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
PUKEY=$($BINARY keys show "${KEYS[1]}" --pubkeyhex --keyring-backend $KEYRING --home "$HOMEDIR")
jq --arg pubkey "$PUKEY" '.app_state["btcbridge"]["params"]["vaults"][0]["pub_key"]=$pubkey' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
VAULT2=$RELAYER
jq --arg vault2 "$VAULT2" '.app_state["btcbridge"]["params"]["vaults"][1]["address"]=$vault2' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
PUKEY=$($BINARY keys show "${KEYS[2]}" --pubkeyhex --keyring-backend $KEYRING --home "$HOMEDIR")
jq --arg pubkey "$PUKEY" '.app_state["btcbridge"]["params"]["vaults"][1]["pub_key"]=$pubkey' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"

# set custom pruning settings
sed -i.bak 's/pruning = "default"/pruning = "custom"/g' "$APP_TOML"
Expand Down
24 changes: 24 additions & 0 deletions proto/side/btcbridge/bitcoin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,29 @@ message UTXO {
bytes pub_key_script = 6;
bool is_coinbase = 7;
bool is_locked = 8;
// rune balances associated with the UTXO
repeated RuneBalance runes = 9;
}

// Rune Balance
message RuneBalance {
// serialized rune id
string id = 1;
// rune amount
string amount = 2;
}

// Rune ID
message RuneId {
// block height
uint64 block = 1;
// tx index
uint32 tx = 2;
}

// Rune Edict
message Edict {
RuneId id = 1;
string amount = 2;
uint32 output = 3;
}
14 changes: 14 additions & 0 deletions proto/side/btcbridge/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ service Query {
rpc QuerySigningRequestByAddress(QuerySigningRequestByAddressRequest) returns (QuerySigningRequestByAddressResponse) {
option (google.api.http).get = "/sideprotocol/side/btcbridge/signing/request/{address}";
}
// QuerySigningRequestByTxHash queries the signing request by the given tx hash.
rpc QuerySigningRequestByTxHash(QuerySigningRequestByTxHashRequest) returns (QuerySigningRequestByTxHashResponse) {
option (google.api.http).get = "/sideprotocol/side/btcbridge/signing/request/{txid}";
}
// UTXOs queries all utxos.
rpc QueryUTXOs(QueryUTXOsRequest) returns (QueryUTXOsResponse) {
option (google.api.http).get = "/sideprotocol/side/btcbridge/utxos";
Expand Down Expand Up @@ -69,6 +73,16 @@ message QuerySigningRequestByAddressResponse {
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QuerySigningRequestByTxHashRequest is request type for the Query/SigningRequestByTxHash RPC method.
message QuerySigningRequestByTxHashRequest {
string txid = 1;
}

// QuerySigningRequestByTxHashResponse is response type for the Query/SigningRequestByTxHash RPC method.
message QuerySigningRequestByTxHashResponse {
BitcoinSigningRequest request = 1;
}

// QueryParamsRequest is request type for the Query/Params RPC method.
message QueryParamsRequest {}

Expand Down
23 changes: 22 additions & 1 deletion proto/side/btcbridge/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ service Msg {
rpc SubmitWithdrawSignatures (MsgSubmitWithdrawSignaturesRequest) returns (MsgSubmitWithdrawSignaturesResponse);
// SubmitWithdrawStatus submits the status of the withdraw transaction.
rpc SubmitWithdrawStatus (MsgSubmitWithdrawStatusRequest) returns (MsgSubmitWithdrawStatusResponse);

// UpdateParams defines a governance operation for updating the x/btcbridge module
// parameters. The authority defaults to the x/gov module account.
//
// Since: cosmos-sdk 0.47
rpc UpdateParams(MsgUpdateParamsRequest) returns (MsgUpdateParamsResponse);
}

// MsgSubmitWithdrawStatusRequest defines the Msg/SubmitWithdrawStatus request type.
Expand Down Expand Up @@ -114,3 +118,20 @@ message MsgSubmitWithdrawSignaturesRequest {
message MsgSubmitWithdrawSignaturesResponse {
}

// MsgUpdateParamsRequest is the Msg/UpdateParams request type.
//
// Since: cosmos-sdk 0.47
message MsgUpdateParamsRequest {
// authority is the address that controls the module (defaults to x/gov unless overwritten).
string authority = 1;

// params defines the x/btcbridge parameters to be updated.
//
// NOTE: All parameters must be supplied.
Params params = 2 [(gogoproto.nullable) = false];
}

// MsgUpdateParamsResponse defines the Msg/UpdateParams response type.
//
// Since: cosmos-sdk 0.47
message MsgUpdateParamsResponse {}
5 changes: 5 additions & 0 deletions testutil/keeper/btc_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/cosmos/cosmos-sdk/store"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/sideprotocol/side/app"
"github.com/sideprotocol/side/x/btcbridge/keeper"
"github.com/sideprotocol/side/x/btcbridge/types"
Expand All @@ -32,10 +34,13 @@ func BtcBridgeKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
registry := codectypes.NewInterfaceRegistry()
cdc := codec.NewProtoCodec(registry)

authority := authtypes.NewModuleAddress(govtypes.ModuleName).String()

k := keeper.NewKeeper(
cdc,
storeKey,
memStoreKey,
authority,
app.BankKeeper,
)

Expand Down
17 changes: 14 additions & 3 deletions x/btcbridge/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

// "strings"

"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/sideprotocol/side/x/btcbridge/types"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -131,8 +132,8 @@ func CmdQueryBlock() *cobra.Command {
// CmdQuerySigningRequest returns the command to query signing request
func CmdQuerySigningRequest() *cobra.Command {
cmd := &cobra.Command{
Use: "signing-request [status or address]",
Short: "Query signing requests by status or address",
Use: "signing-request [status | address | tx hash]",
Short: "Query signing requests by status, address or tx hash",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
Expand All @@ -146,7 +147,17 @@ func CmdQuerySigningRequest() *cobra.Command {
if err != nil {
_, err = sdk.AccAddressFromBech32(args[0])
if err != nil {
return err
_, err := chainhash.NewHashFromStr(args[0])
if err != nil {
return fmt.Errorf("invalid arg, neither status, address nor tx hash: %s", args[0])
}

res, err := queryClient.QuerySigningRequestByTxHash(cmd.Context(), &types.QuerySigningRequestByTxHashRequest{Txid: args[0]})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
}

res, err := queryClient.QuerySigningRequestByAddress(cmd.Context(), &types.QuerySigningRequestByAddressRequest{Address: args[0]})
Expand Down
5 changes: 4 additions & 1 deletion x/btcbridge/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type (
storeKey storetypes.StoreKey
memKey storetypes.StoreKey

authority string

bankKeeper types.BankKeeper
}
)
Expand All @@ -27,13 +29,14 @@ func NewKeeper(
cdc codec.BinaryCodec,
storeKey,
memKey storetypes.StoreKey,

authority string,
bankKeeper types.BankKeeper,
) *Keeper {
return &Keeper{
cdc: cdc,
storeKey: storeKey,
memKey: memKey,
authority: authority,
bankKeeper: bankKeeper,
BaseUTXOKeeper: *NewBaseUTXOKeeper(cdc, storeKey),
}
Expand Down
Loading

0 comments on commit 334354f

Please sign in to comment.