-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make staker command to use global parameters library (#170)
* Make staker commands to use global parameters library
- Loading branch information
1 parent
d88515b
commit c853313
Showing
11 changed files
with
568 additions
and
477 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,99 @@ | ||
package transaction | ||
|
||
import ( | ||
"encoding/hex" | ||
"fmt" | ||
"math" | ||
|
||
"github.com/babylonchain/babylon/btcstaking" | ||
"github.com/btcsuite/btcd/btcec/v2" | ||
"github.com/btcsuite/btcd/btcec/v2/schnorr" | ||
"github.com/btcsuite/btcd/btcutil" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
func parseSchnorPubKeyFromCliCtx(ctx *cli.Context, flagName string) (*btcec.PublicKey, error) { | ||
pkHex := ctx.String(flagName) | ||
return parseSchnorPubKeyFromHex(pkHex) | ||
} | ||
|
||
func parseSchnorPubKeyFromHex(pkHex string) (*btcec.PublicKey, error) { | ||
pkBytes, err := hex.DecodeString(pkHex) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
pk, err := schnorr.ParsePubKey(pkBytes) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return pk, nil | ||
} | ||
|
||
func parseAmountFromCliCtx(ctx *cli.Context, flagName string) (btcutil.Amount, error) { | ||
amt := ctx.Int64(flagName) | ||
|
||
if amt <= 0 { | ||
return 0, fmt.Errorf("staking amount should be greater than 0") | ||
} | ||
|
||
return btcutil.Amount(amt), nil | ||
} | ||
|
||
func parseLockTimeBlocksFromCliCtx(ctx *cli.Context, flagName string) (uint16, error) { | ||
timeBlocks := ctx.Int64(flagName) | ||
|
||
if timeBlocks <= 0 { | ||
return 0, fmt.Errorf("staking time blocks should be greater than 0") | ||
} | ||
|
||
if timeBlocks > math.MaxUint16 { | ||
return 0, fmt.Errorf("staking time blocks should be less or equal to %d", math.MaxUint16) | ||
} | ||
|
||
return uint16(timeBlocks), nil | ||
} | ||
|
||
func parseCovenantKeysFromCliCtx(ctx *cli.Context) ([]*btcec.PublicKey, error) { | ||
covenantMembersPks := ctx.StringSlice(covenantMembersPksFlag) | ||
return parseCovenantKeysFromSlice(covenantMembersPks) | ||
} | ||
|
||
func parseCovenantKeysFromSlice(covenantMembersPks []string) ([]*btcec.PublicKey, error) { | ||
covenantPubKeys := make([]*btcec.PublicKey, len(covenantMembersPks)) | ||
|
||
for i, fpPk := range covenantMembersPks { | ||
fpPkBytes, err := hex.DecodeString(fpPk) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
fpSchnorrKey, err := schnorr.ParsePubKey(fpPkBytes) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
covenantPubKeys[i] = fpSchnorrKey | ||
} | ||
|
||
return covenantPubKeys, nil | ||
} | ||
|
||
func parseMagicBytesFromCliCtx(ctx *cli.Context) ([]byte, error) { | ||
magicBytesHex := ctx.String(magicBytesFlag) | ||
return parseMagicBytesFromHex(magicBytesHex) | ||
} | ||
|
||
func parseMagicBytesFromHex(magicBytesHex string) ([]byte, error) { | ||
magicBytes, err := hex.DecodeString(magicBytesHex) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if len(magicBytes) != btcstaking.MagicBytesLen { | ||
return nil, fmt.Errorf("magic bytes should be of length %d", btcstaking.MagicBytesLen) | ||
} | ||
|
||
return magicBytes, nil | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.