-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #153 from NodeFactoryIo/mmuftic/send-all-funds-on-…
…payout Send all funds on payout
- Loading branch information
Showing
15 changed files
with
357 additions
and
74 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
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,45 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"github.com/NodeFactoryIo/vedran/internal/ui/prompts" | ||
"strconv" | ||
) | ||
|
||
func ValidatePayoutFlags( | ||
payoutReward string, | ||
payoutAddress string, | ||
showPrompts bool, | ||
) (float64, error) { | ||
var err error | ||
var rewardAsFloat64 float64 | ||
|
||
// if total reward is determined as wallet balance | ||
if payoutReward == "-1" { | ||
if payoutAddress == "" { | ||
return 0, errors.New("Unable to set reward amount to entire wallet balance if fee address not provided") | ||
} else { | ||
if showPrompts { | ||
confirmed, err := prompts.ShowConfirmationPrompt( | ||
fmt.Sprintf("You choose that reward amount is defined as entire balance on lb wallet!" + | ||
"On payout entire balance will be distributed as reward and lb fee will be sent to address %s", | ||
payoutAddress), | ||
) | ||
if err != nil { | ||
return 0, err | ||
} | ||
if !confirmed { | ||
return 0, errors.New("Payout configuration canceled") | ||
} | ||
} | ||
} | ||
} else { | ||
rewardAsFloat64, err = strconv.ParseFloat(payoutReward, 64) | ||
if err != nil || rewardAsFloat64 < -1 { | ||
return 0, errors.New("invalid total reward value") | ||
} | ||
} | ||
|
||
return rewardAsFloat64, 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,49 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestValidatePayoutFlags(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
payoutReward string | ||
payoutAddress string | ||
validateReturns float64 | ||
validateError bool | ||
}{ | ||
{ | ||
name: "valid flags", | ||
payoutReward: "1000", | ||
payoutAddress: "", | ||
validateReturns: float64(1000), | ||
validateError: false, | ||
}, | ||
{ | ||
name: "invalid flags, missing reward address", | ||
payoutReward: "-1", | ||
payoutAddress: "", | ||
validateReturns: float64(0), | ||
validateError: true, | ||
}, | ||
{ | ||
name: "invalid flags, negative reward", | ||
payoutReward: "-100", | ||
payoutAddress: "", | ||
validateReturns: float64(0), | ||
validateError: true, | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
rewAsFloat64, err := ValidatePayoutFlags(test.payoutReward, test.payoutAddress, false) | ||
assert.Equal(t, test.validateReturns, rewAsFloat64) | ||
if test.validateError { | ||
assert.Error(t, err) | ||
} else { | ||
assert.NoError(t, err) | ||
} | ||
}) | ||
} | ||
} |
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,18 @@ | ||
package api | ||
|
||
import ( | ||
gsrpc "github.com/NodeFactoryIo/go-substrate-rpc-client" | ||
"github.com/NodeFactoryIo/go-substrate-rpc-client/types" | ||
) | ||
|
||
func InitializeSubstrateAPI(substrateRPCUrl string) (*gsrpc.SubstrateAPI, error) { | ||
api, err := gsrpc.NewSubstrateAPI(substrateRPCUrl) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
opts := types.SerDeOptions{NoPalletIndices: true} | ||
types.SetSerDeOptions(opts) | ||
|
||
return api, nil | ||
} |
Oops, something went wrong.