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

Add runes support #101

Closed
wants to merge 17 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*.swl
*.swm
*.swn
# .vscode
.vscode
.idea
*.pyc
*.exe
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
10 changes: 8 additions & 2 deletions local_node_dev.sh
Original file line number Diff line number Diff line change
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;
}
16 changes: 16 additions & 0 deletions proto/side/btcbridge/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ service Query {
rpc QuerySigningRequest(QuerySigningRequestRequest) returns (QuerySigningRequestResponse) {
option (google.api.http).get = "/sideprotocol/side/btcbridge/signing/request";
}
// QuerySigningRequestByAddress queries the signing request by the given address.
rpc QuerySigningRequestByAddress(QuerySigningRequestByAddressRequest) returns (QuerySigningRequestByAddressResponse) {
option (google.api.http).get = "/sideprotocol/side/btcbridge/signing/request/{address}";
}
// UTXOs queries all utxos.
rpc QueryUTXOs(QueryUTXOsRequest) returns (QueryUTXOsResponse) {
option (google.api.http).get = "/sideprotocol/side/btcbridge/utxos";
Expand All @@ -53,6 +57,18 @@ message QuerySigningRequestResponse {
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QuerySigningRequestByAddressRequest is request type for the Query/SigningRequestByAddress RPC method.
message QuerySigningRequestByAddressRequest {
string address = 1;
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// QuerySigningRequestByAddressResponse is response type for the Query/SigningRequestByAddress RPC method.
message QuerySigningRequestByAddressResponse {
repeated BitcoinSigningRequest requests = 1;
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

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

Expand Down
2 changes: 1 addition & 1 deletion proto/side/btcbridge/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ message MsgWithdrawBitcoinRequest {
// withdraw amount in satoshi, etc: 100000000sat = 1btc
string amount = 2;
// fee rate in sats/vB
int64 fee_rate = 3;
string fee_rate = 3;
}

// MsgWithdrawBitcoinResponse defines the Msg/WithdrawBitcoin response type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
"github.com/stretchr/testify/require"
)

func BtcLightClientKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
func BtcBridgeKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
app := app.InitSideTestApp(false)

storeKey := sdk.NewKVStoreKey(types.StoreKey)
memStoreKey := storetypes.NewMemoryStoreKey(types.ModuleName)
memStoreKey := storetypes.NewMemoryStoreKey(types.MemStoreKey)

db := tmdb.NewMemDB()
stateStore := store.NewCommitMultiStore(db)
Expand Down
24 changes: 17 additions & 7 deletions x/btcbridge/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
queryClient := types.NewQueryClient(clientCtx)

height, err := strconv.ParseUint(args[0], 10, 64)

Check failure on line 108 in x/btcbridge/client/cli/query.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)

Check failure on line 108 in x/btcbridge/client/cli/query.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)
if err != nil {
res, err := queryClient.QueryBlockHeaderByHash(cmd.Context(), &types.QueryBlockHeaderByHashRequest{Hash: args[0]})
if err != nil {
Expand All @@ -132,8 +132,8 @@
// CmdQuerySigningRequest returns the command to query signing request
func CmdQuerySigningRequest() *cobra.Command {
cmd := &cobra.Command{
Use: "signing-request [status]",
Short: "Query all signing requests",
Use: "signing-request [status or address]",
Short: "Query signing requests by status or address",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
Expand All @@ -145,7 +145,17 @@

status, err := strconv.ParseInt(args[0], 10, 32)
if err != nil {
return err
_, err = sdk.AccAddressFromBech32(args[0])
if err != nil {
return err
}

res, err := queryClient.QuerySigningRequestByAddress(cmd.Context(), &types.QuerySigningRequestByAddressRequest{Address: args[0]})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
}

res, err := queryClient.QuerySigningRequest(cmd.Context(), &types.QuerySigningRequestRequest{Status: types.SigningStatus(status)})
Expand Down Expand Up @@ -174,10 +184,10 @@
}

if len(args) == 0 {
return queryUTXOs(&clientCtx, cmd.Context())
return queryUTXOs(cmd.Context(), &clientCtx)
}

return queryUTXOsByAddr(&clientCtx, cmd.Context(), args[0])
return queryUTXOsByAddr(cmd.Context(), &clientCtx, args[0])
},
}

Expand All @@ -186,7 +196,7 @@
return cmd
}

func queryUTXOs(clientCtx *client.Context, cmdCtx context.Context) error {
func queryUTXOs(cmdCtx context.Context, clientCtx *client.Context) error {
queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.QueryUTXOs(cmdCtx, &types.QueryUTXOsRequest{})
Expand All @@ -197,7 +207,7 @@
return clientCtx.PrintProto(res)
}

func queryUTXOsByAddr(clientCtx *client.Context, cmdCtx context.Context, addr string) error {
func queryUTXOsByAddr(cmdCtx context.Context, clientCtx *client.Context, addr string) error {
queryClient := types.NewQueryClient(clientCtx)

_, err := sdk.AccAddressFromBech32(addr)
Expand Down
8 changes: 1 addition & 7 deletions x/btcbridge/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"encoding/json"
"fmt"
"os"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -51,7 +50,7 @@
Short: "Submit Bitcoin block headers to the chain",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {

Check failure on line 53 in x/btcbridge/client/cli/tx.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)

Check failure on line 53 in x/btcbridge/client/cli/tx.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not `gofumpt`-ed (gofumpt)
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
Expand Down Expand Up @@ -130,15 +129,10 @@
return fmt.Errorf("invalid amount")
}

feeRate, err := strconv.ParseInt(args[1], 10, 64)
if err != nil {
return fmt.Errorf("invalid fee rate")
}

msg := types.NewMsgWithdrawBitcoinRequest(
clientCtx.GetFromAddress().String(),
args[0],
feeRate,
args[1],
)

if err := msg.ValidateBasic(); err != nil {
Expand Down
7 changes: 5 additions & 2 deletions x/btcbridge/genesis.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package btclightclient
package btcbridge

import (
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -12,7 +12,10 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
k.SetParams(ctx, genState.Params)
k.SetBestBlockHeader(ctx, genState.BestBlockHeader)
if len(genState.BlockHeaders) > 0 {
k.SetBlockHeaders(ctx, genState.BlockHeaders)
err := k.SetBlockHeaders(ctx, genState.BlockHeaders)
if err != nil {
panic(err)
}
}
// import utxos
for _, utxo := range genState.Utxos {
Expand Down
14 changes: 7 additions & 7 deletions x/btcbridge/genesis_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package btclightclient_test
package btcbridge_test

// Path: x/btclightclient/genesis_test.go
// Path: x/btcbridge/genesis_test.go

import (
"bytes"
Expand All @@ -11,7 +11,7 @@ import (
"github.com/btcsuite/btcd/wire"
keepertest "github.com/sideprotocol/side/testutil/keeper"
"github.com/sideprotocol/side/testutil/nullify"
btclightclient "github.com/sideprotocol/side/x/btcbridge"
"github.com/sideprotocol/side/x/btcbridge"
"github.com/sideprotocol/side/x/btcbridge/types"
"github.com/stretchr/testify/require"
)
Expand All @@ -27,9 +27,9 @@ func TestGenesis(t *testing.T) {
// this line is used by starport scaffolding # genesis/test/state
}

k, ctx := keepertest.BtcLightClientKeeper(t)
btclightclient.InitGenesis(ctx, *k, genesisState)
got := btclightclient.ExportGenesis(ctx, *k)
k, ctx := keepertest.BtcBridgeKeeper(t)
btcbridge.InitGenesis(ctx, *k, genesisState)
got := btcbridge.ExportGenesis(ctx, *k)
require.NotNil(t, got)

nullify.Fill(&genesisState)
Expand All @@ -43,7 +43,7 @@ func TestGenesis(t *testing.T) {

// // test tx: https://blockchain.info/tx/b657e22827039461a9493ede7bdf55b01579254c1630b0bfc9185ec564fc05ab?format=json

// k, ctx := keepertest.BtcLightClientKeeper(t)
// k, ctx := keepertest.BtcbridgeClientKeeper(t)

// txHex := "02000000000101e5df234dbeff74d6da14754ebeea8ab0e2f60b1884566846cf6b36e8ceb5f5350100000000fdffffff02f0490200000000001600142ac13073e8d491428790481321a636696d00107681d7e205000000001600142bf3aa186cbdcbe88b70a67edcd5a32ce5e8e6d8024730440220081ee61d749ce8cedcf6eedde885579af2eb65ca67d29e6ae2c37109d81cbbb202203a1891ce45f91f159ccf04348ef37a3d1a12d89e5e01426e061326057e6c128d012103036bbdd77c9a932f37bd66175967c7fb7eb75ece06b87c1ad1716770cb3ca4ee79fc2a00"
// prevTxHex := "0200000000010183372652f2af9ab34b3a003efada6b054c75583185ac130de72599dfdf4e462b0100000000fdffffff02f0490200000000001600142ac13073e8d491428790481321a636696d001076a64ee50500000000160014a03614eef338681373de94a2dc2574de55da1980024730440220274250f6036bea0947daf4455ab4976f81721257d163fd952fb5b0c70470edc602202fba816be260219bbc40a8983c459cf05cf2209bf1e62e7ccbf78aec54db607f0121031cee21ef69fe68b240c3032616fa310c6a60a856c0a7e0c1298815c92fb2c61788fb2a00"
Expand Down
Loading
Loading