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