forked from Lorenzo-Protocol/lorenzo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
2,791 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
syntax = "proto3"; | ||
package lorenzo.btcstaking.v1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
|
||
option go_package = "github.com/Lorenzo-Protocol/lorenzo/x/btcstaking/types"; | ||
|
||
// GenesisState defines the btcstaking module's genesis state. | ||
message GenesisState { | ||
string btc_receiving_addr = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
syntax = "proto3"; | ||
package lorenzo.btcstaking.v1; | ||
|
||
import "cosmos/msg/v1/msg.proto"; | ||
import "cosmos_proto/cosmos.proto"; | ||
import "gogoproto/gogo.proto"; | ||
//import "cosmos/staking/v1beta1/staking.proto"; | ||
|
||
option go_package = "github.com/Lorenzo-Protocol/lorenzo/x/btcstaking/types"; | ||
|
||
message BTCStakingRecord { | ||
bytes tx_hash = 1; | ||
uint64 amount = 2; | ||
bytes mint_to_addr = 3; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
syntax = "proto3"; | ||
package lorenzo.btcstaking.v1; | ||
|
||
import "cosmos/msg/v1/msg.proto"; | ||
import "cosmos_proto/cosmos.proto"; | ||
import "gogoproto/gogo.proto"; | ||
//import "cosmos/staking/v1beta1/staking.proto"; | ||
|
||
option go_package = "github.com/Lorenzo-Protocol/lorenzo/x/btcstaking/types"; | ||
|
||
// Msg defines the Msg service. | ||
// TODO: handle unbonding tx with full witness | ||
service Msg { | ||
option (cosmos.msg.v1.service) = true; | ||
|
||
// CreateBTCDelegation creates a new BTC delegation | ||
rpc CreateBTCStaking(MsgCreateBTCStaking) returns (MsgCreateBTCStakingResponse); | ||
} | ||
|
||
message TransactionKey { | ||
uint32 index = 1; | ||
bytes hash = 2 | ||
[ (gogoproto.customtype) = | ||
"github.com/Lorenzo-Protocol/lorenzo/types.BTCHeaderHashBytes" ]; | ||
} | ||
|
||
// TransactionInfo is the info of a tx on Bitcoin, | ||
// including | ||
// - the position of the tx on BTC blockchain | ||
// - the full tx content | ||
// - the Merkle proof that this tx is on the above position | ||
message TransactionInfo { | ||
// key is the position (txIdx, blockHash) of this tx on BTC blockchain | ||
// Although it is already a part of SubmissionKey, we store it here again | ||
// to make TransactionInfo self-contained. | ||
// For example, storing the key allows TransactionInfo to not relay on | ||
// the fact that TransactionInfo will be ordered in the same order as | ||
// TransactionKeys in SubmissionKey. | ||
TransactionKey key = 1; | ||
// transaction is the full transaction in bytes | ||
bytes transaction = 2; | ||
// proof is the Merkle proof that this tx is included in the position in `key` | ||
// TODO: maybe it could use here better format as we already processed and | ||
// validated the proof? | ||
bytes proof = 3; | ||
} | ||
|
||
message MsgCreateBTCStaking { | ||
option (cosmos.msg.v1.signer) = "signer"; | ||
string signer = 1; | ||
TransactionInfo staking_tx = 2; | ||
} | ||
|
||
message MsgCreateBTCStakingResponse {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package cli | ||
|
||
import ( | ||
//"encoding/hex" | ||
"fmt" | ||
//"strings" | ||
|
||
//sdkmath "cosmossdk.io/math" | ||
"github.com/cosmos/cosmos-sdk/client" | ||
/*"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" | ||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"*/ | ||
"github.com/spf13/cobra" | ||
|
||
//lrz "github.com/Lorenzo-Protocol/lorenzo/types" | ||
"github.com/Lorenzo-Protocol/lorenzo/x/btcstaking/types" | ||
) | ||
|
||
const ( | ||
FlagMoniker = "moniker" | ||
FlagIdentity = "identity" | ||
FlagWebsite = "website" | ||
FlagSecurityContact = "security-contact" | ||
FlagDetails = "details" | ||
FlagCommissionRate = "commission-rate" | ||
) | ||
|
||
// GetTxCmd returns the transaction commands for this module | ||
func GetTxCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: types.ModuleName, | ||
Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), | ||
DisableFlagParsing: true, | ||
SuggestionsMinimumDistance: 2, | ||
RunE: client.ValidateCmd, | ||
} | ||
|
||
//FIXME: add command | ||
cmd.AddCommand() | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"math" | ||
|
||
sdkmath "cosmossdk.io/math" | ||
"github.com/btcsuite/btcd/btcutil" | ||
) | ||
|
||
func parseLockTime(str string) (uint16, error) { | ||
num, ok := sdkmath.NewIntFromString(str) | ||
|
||
if !ok { | ||
return 0, fmt.Errorf("invalid staking time: %s", str) | ||
} | ||
|
||
if !num.IsUint64() { | ||
return 0, fmt.Errorf("staking time is not valid uint") | ||
} | ||
|
||
asUint64 := num.Uint64() | ||
|
||
if asUint64 > math.MaxUint16 { | ||
return 0, fmt.Errorf("staking time is too large. Max is %d", math.MaxUint16) | ||
} | ||
|
||
return uint16(asUint64), nil | ||
} | ||
|
||
func parseBtcAmount(str string) (btcutil.Amount, error) { | ||
num, ok := sdkmath.NewIntFromString(str) | ||
|
||
if !ok { | ||
return 0, fmt.Errorf("invalid staking value: %s", str) | ||
} | ||
|
||
if num.IsNegative() { | ||
return 0, fmt.Errorf("staking value is negative") | ||
} | ||
|
||
if !num.IsInt64() { | ||
return 0, fmt.Errorf("staking value is not valid uint") | ||
} | ||
|
||
asInt64 := num.Int64() | ||
|
||
return btcutil.Amount(asInt64), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package keeper | ||
|
||
import ( | ||
"github.com/Lorenzo-Protocol/lorenzo/x/btcstaking/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// SetBTCReceivingAddr sets the x/btcstaking module parameters. | ||
func (k Keeper) SetBTCReceivingAddr(ctx sdk.Context, p string) error { | ||
store := ctx.KVStore(k.storeKey) | ||
bz := []byte(p) | ||
store.Set(types.BTCReceivingAddrKey, bz) | ||
return nil | ||
} | ||
|
||
// GetBTCReceivingAddr returns the current x/btcstaking module parameters. | ||
func (k Keeper) GetBTCReceivingAddr(ctx sdk.Context) (p string) { | ||
store := ctx.KVStore(k.storeKey) | ||
bz := store.Get(types.BTCReceivingAddrKey) | ||
if bz == nil { | ||
return p | ||
} | ||
p = string(bz) | ||
return p | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package keeper | ||
|
||
import ( | ||
"github.com/Lorenzo-Protocol/lorenzo/x/btcstaking/types" | ||
"github.com/btcsuite/btcd/chaincfg/chainhash" | ||
"github.com/cosmos/cosmos-sdk/store/prefix" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
func (k Keeper) addBTCStakingRecord(ctx sdk.Context, btcStk *types.BTCStakingRecord) error { | ||
store := k.btcStakingRecordStore(ctx) | ||
var btcStkKey = btcStk.TxHash | ||
store.Set(btcStkKey, k.cdc.MustMarshal(btcStk)) | ||
return nil | ||
} | ||
|
||
func (k Keeper) getBTCStakingRecord(ctx sdk.Context, txHash chainhash.Hash) *types.BTCStakingRecord { | ||
store := k.btcStakingRecordStore(ctx) | ||
btcStakingRecordBytes := store.Get(txHash[:]) | ||
if len(btcStakingRecordBytes) == 0 { | ||
return nil | ||
} | ||
var btcStkRecord types.BTCStakingRecord | ||
k.cdc.MustUnmarshal(btcStakingRecordBytes, &btcStkRecord) | ||
return &btcStkRecord | ||
} | ||
|
||
func (k Keeper) btcStakingRecordStore(ctx sdk.Context) prefix.Store { | ||
kvStore := ctx.KVStore(k.storeKey) | ||
return prefix.NewStore(kvStore, types.BTCStakingRecordKey) | ||
} |
Oops, something went wrong.