mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
Add validations to CLI flags
This commit is contained in:
parent
8e8f7c9b32
commit
484c17ebb1
12
.github/workflows/deploy.yaml
vendored
12
.github/workflows/deploy.yaml
vendored
@ -1,7 +1,7 @@
|
||||
name: Build and upload assets
|
||||
on:
|
||||
release:
|
||||
types: [ published ]
|
||||
types: [published]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
@ -9,7 +9,7 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
name: Building, ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Fix CRLF on Windows
|
||||
@ -19,7 +19,6 @@ jobs:
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@v2
|
||||
|
||||
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
@ -31,7 +30,7 @@ jobs:
|
||||
# `-tags netgo,osusergo` means use pure go replacements for "os/user" and "net"
|
||||
# `-s -w` strips the binary to produce smaller size binaries
|
||||
run: |
|
||||
go build -v -ldflags="-s -w -extldflags=-static" -tags netgo,osusergo -o ./bin/ . ./cmd/...
|
||||
go build -v -ldflags="-s -w -extldflags=-static" -tags netgo,osusergo -o ./bin/ ./cmd/...
|
||||
archive="bin/kaspad-${{ github.event.release.tag_name }}-linux.zip"
|
||||
asset_name="kaspad-${{ github.event.release.tag_name }}-linux.zip"
|
||||
zip -r "${archive}" ./bin/*
|
||||
@ -42,7 +41,7 @@ jobs:
|
||||
if: runner.os == 'Windows'
|
||||
shell: bash
|
||||
run: |
|
||||
go build -v -ldflags="-s -w" -o bin/ . ./cmd/...
|
||||
go build -v -ldflags="-s -w" -o bin/ ./cmd/...
|
||||
archive="bin/kaspad-${{ github.event.release.tag_name }}-win64.zip"
|
||||
asset_name="kaspad-${{ github.event.release.tag_name }}-win64.zip"
|
||||
powershell "Compress-Archive bin/* \"${archive}\""
|
||||
@ -52,14 +51,13 @@ jobs:
|
||||
- name: Build on MacOS
|
||||
if: runner.os == 'macOS'
|
||||
run: |
|
||||
go build -v -ldflags="-s -w" -o ./bin/ . ./cmd/...
|
||||
go build -v -ldflags="-s -w" -o ./bin/ ./cmd/...
|
||||
archive="bin/kaspad-${{ github.event.release.tag_name }}-osx.zip"
|
||||
asset_name="kaspad-${{ github.event.release.tag_name }}-osx.zip"
|
||||
zip -r "${archive}" ./bin/*
|
||||
echo "archive=${archive}" >> $GITHUB_ENV
|
||||
echo "asset_name=${asset_name}" >> $GITHUB_ENV
|
||||
|
||||
|
||||
- name: Upload release asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
|
@ -360,13 +360,25 @@ func parseCommandLine() (subCommand string, config interface{}) {
|
||||
if err != nil {
|
||||
printErrorAndExit(err)
|
||||
}
|
||||
config = bumpFeeConf
|
||||
case bumpFeeUnsignedSubCmd:
|
||||
combineNetworkFlags(&bumpFeeConf.NetworkFlags, &cfg.NetworkFlags)
|
||||
err := bumpFeeConf.ResolveNetwork(parser)
|
||||
|
||||
err = validateBumpFeeConfig(bumpFeeConf)
|
||||
if err != nil {
|
||||
printErrorAndExit(err)
|
||||
}
|
||||
|
||||
config = bumpFeeConf
|
||||
case bumpFeeUnsignedSubCmd:
|
||||
combineNetworkFlags(&bumpFeeUnsignedConf.NetworkFlags, &cfg.NetworkFlags)
|
||||
err := bumpFeeUnsignedConf.ResolveNetwork(parser)
|
||||
if err != nil {
|
||||
printErrorAndExit(err)
|
||||
}
|
||||
|
||||
err = validateBumpFeeUnsignedConfig(bumpFeeUnsignedConf)
|
||||
if err != nil {
|
||||
printErrorAndExit(err)
|
||||
}
|
||||
|
||||
config = bumpFeeUnsignedConf
|
||||
}
|
||||
|
||||
@ -388,8 +400,8 @@ func validateCreateUnsignedTransactionConf(conf *createUnsignedTransactionConfig
|
||||
return errors.New("--fee-rate must be a positive number")
|
||||
}
|
||||
|
||||
if conf.MaxFeeRate > 0 && conf.FeeRate > 0 {
|
||||
return errors.New("at most one of '--max-fee-rate' or '--fee-rate' can be specified")
|
||||
if boolToUint8(conf.MaxFeeRate > 0)+boolToUint8(conf.FeeRate > 0)+boolToUint8(conf.MaxFee > 0) > 1 {
|
||||
return errors.New("at most one of '--max-fee-rate', '--fee-rate' or '--max-fee' can be specified")
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -410,13 +422,52 @@ func validateSendConfig(conf *sendConfig) error {
|
||||
return errors.New("--fee-rate must be a positive number")
|
||||
}
|
||||
|
||||
if conf.MaxFeeRate > 0 && conf.FeeRate > 0 {
|
||||
return errors.New("at most one of '--max-fee-rate' or '--fee-rate' can be specified")
|
||||
if boolToUint8(conf.MaxFeeRate > 0)+boolToUint8(conf.FeeRate > 0)+boolToUint8(conf.MaxFee > 0) > 1 {
|
||||
return errors.New("at most one of '--max-fee-rate', '--fee-rate' or '--max-fee' can be specified")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateBumpFeeConfig(conf *bumpFeeConfig) error {
|
||||
if conf.MaxFeeRate < 0 {
|
||||
return errors.New("--max-fee-rate must be a positive number")
|
||||
}
|
||||
|
||||
if conf.FeeRate < 0 {
|
||||
return errors.New("--fee-rate must be a positive number")
|
||||
}
|
||||
|
||||
if boolToUint8(conf.MaxFeeRate > 0)+boolToUint8(conf.FeeRate > 0)+boolToUint8(conf.MaxFee > 0) > 1 {
|
||||
return errors.New("at most one of '--max-fee-rate', '--fee-rate' or '--max-fee' can be specified")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateBumpFeeUnsignedConfig(conf *bumpFeeUnsignedConfig) error {
|
||||
if conf.MaxFeeRate < 0 {
|
||||
return errors.New("--max-fee-rate must be a positive number")
|
||||
}
|
||||
|
||||
if conf.FeeRate < 0 {
|
||||
return errors.New("--fee-rate must be a positive number")
|
||||
}
|
||||
|
||||
if boolToUint8(conf.MaxFeeRate > 0)+boolToUint8(conf.FeeRate > 0)+boolToUint8(conf.MaxFee > 0) > 1 {
|
||||
return errors.New("at most one of '--max-fee-rate', '--fee-rate' or '--max-fee' can be specified")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func boolToUint8(b bool) uint8 {
|
||||
if b {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func combineNetworkFlags(dst, src *config.NetworkFlags) {
|
||||
dst.Testnet = dst.Testnet || src.Testnet
|
||||
dst.Simnet = dst.Simnet || src.Simnet
|
||||
|
Loading…
x
Reference in New Issue
Block a user