add flag to manually refill credits into sync wallet

This commit is contained in:
Alex Grintsvayg 2018-03-12 16:58:37 -04:00
parent 263a6301a6
commit 8dd15ee220
No known key found for this signature in database
GPG key ID: AEB3F089F86A22B5
3 changed files with 15 additions and 3 deletions

View file

@ -18,6 +18,7 @@ func init() {
ytSyncCmd.Flags().BoolVar(&stopOnError, "stop-on-error", false, "If a publish fails, stop all publishing and exit")
ytSyncCmd.Flags().IntVar(&maxTries, "max-tries", defaultMaxTries, "Number of times to try a publish that fails")
ytSyncCmd.Flags().BoolVar(&takeOverExistingChannel, "takeover-existing-channel", false, "If channel exists and we don't own it, take over the channel")
ytSyncCmd.Flags().IntVar(&refill, "refill", 0, "Also add this many credits to the wallet")
RootCmd.AddCommand(ytSyncCmd)
}
@ -27,6 +28,7 @@ var (
stopOnError bool
maxTries int
takeOverExistingChannel bool
refill int
)
func ytsync(cmd *cobra.Command, args []string) {
@ -59,6 +61,7 @@ func ytsync(cmd *cobra.Command, args []string) {
MaxTries: maxTries,
ConcurrentVideos: 1,
TakeOverExistingChannel: takeOverExistingChannel,
Refill: refill,
}
err := s.FullCycle()

View file

@ -46,11 +46,19 @@ func (s *Sync) walletSetup() error {
minBalance := (float64(numOnSource)-float64(numPublished))*publishAmount + channelClaimAmount
amountToAdd, _ := decimal.NewFromFloat(minBalance).Sub(balance).Float64()
amountToAdd *= 1.5 // add 50% margin for fees, future publishes, etc
if s.Refill > 0 {
if amountToAdd < 0 {
amountToAdd = float64(s.Refill)
} else {
amountToAdd += float64(s.Refill)
}
}
if amountToAdd > 0 {
amountToAdd *= 1.5 // add 50% margin for fees, future publishes, etc
if amountToAdd < 1 {
amountToAdd = 1
amountToAdd = 1 // no reason to bother adding less than 1 credit
}
s.addCredits(amountToAdd)
}

View file

@ -55,6 +55,7 @@ type Sync struct {
MaxTries int
ConcurrentVideos int
TakeOverExistingChannel bool
Refill int
daemon *jsonrpc.Client
claimAddress string
@ -123,7 +124,7 @@ func (s *Sync) FullCycle() error {
signal.Notify(interruptChan, os.Interrupt, syscall.SIGTERM)
go func() {
<-interruptChan
log.Println("Got interrupt signal. Will shut down after current publishes finish")
log.Println("Got interrupt signal, shutting down (if publishing, will shut down after current publish)")
s.stop.Stop()
}()