Skip to content

Commit

Permalink
Merge branch 'master' into green/ge-piece-does-not-exist
Browse files Browse the repository at this point in the history
  • Loading branch information
mobyvb committed Nov 5, 2019
2 parents d41f886 + d6b5d49 commit b5f03e1
Show file tree
Hide file tree
Showing 49 changed files with 3,290 additions and 356 deletions.
133 changes: 123 additions & 10 deletions cmd/inspector/main.go
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"strconv"
"strings"
"time"

prompt "github.com/segmentio/go-prompt"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -79,15 +80,36 @@ var (
Args: cobra.MinimumNArgs(4),
RunE: SegmentHealth,
}
paymentsCmd = &cobra.Command{
Use: "payments",
Short: "commands for payments",
}
prepareInvoiceRecordsCmd = &cobra.Command{
Use: "prepare-invoice-records <period>",
Short: "Prepares invoice project records that will be used during invoice line items creation",
Args: cobra.MinimumNArgs(1),
RunE: prepareInvoiceRecords,
}
createInvoiceItemsCmd = &cobra.Command{
Use: "create-invoice-items",
Short: "Creates stripe invoice line items for not consumed project records",
RunE: createInvoiceItems,
}
createInvoicesCmd = &cobra.Command{
Use: "create-invoices",
Short: "Creates stripe invoices for all stripe customers known to satellite",
RunE: createInvoices,
}
)

// Inspector gives access to overlay.
type Inspector struct {
conn *rpc.Conn
identity *identity.FullIdentity
overlayclient rpc.OverlayInspectorClient
irrdbclient rpc.IrreparableInspectorClient
healthclient rpc.HealthInspectorClient
conn *rpc.Conn
identity *identity.FullIdentity
overlayclient rpc.OverlayInspectorClient
irrdbclient rpc.IrreparableInspectorClient
healthclient rpc.HealthInspectorClient
paymentsClient rpc.PaymentsClient
}

// NewInspector creates a new gRPC inspector client for access to overlay.
Expand All @@ -108,11 +130,12 @@ func NewInspector(address, path string) (*Inspector, error) {
}

return &Inspector{
conn: conn,
identity: id,
overlayclient: conn.OverlayInspectorClient(),
irrdbclient: conn.IrreparableInspectorClient(),
healthclient: conn.HealthInspectorClient(),
conn: conn,
identity: id,
overlayclient: conn.OverlayInspectorClient(),
irrdbclient: conn.IrreparableInspectorClient(),
healthclient: conn.HealthInspectorClient(),
paymentsClient: conn.PaymentsClient(),
}, nil
}

Expand Down Expand Up @@ -423,14 +446,104 @@ func sortSegments(segments []*pb.IrreparableSegment) map[string][]*pb.Irreparabl
return objects
}

func prepareInvoiceRecords(cmd *cobra.Command, args []string) error {
i, err := NewInspector(*Addr, *IdentityPath)
if err != nil {
return ErrInspectorDial.Wrap(err)
}

defer func() { err = errs.Combine(err, i.Close()) }()

period, err := parseDateString(args[0])
if err != nil {
return ErrArgs.New("invalid period specified: %v", err)
}

_, err = i.paymentsClient.PrepareInvoiceRecords(context.Background(),
&pb.PrepareInvoiceRecordsRequest{
Period: period,
},
)
if err != nil {
return err
}

fmt.Println("successfully created invoice project records")
return nil
}

func createInvoiceItems(cmd *cobra.Command, args []string) error {
i, err := NewInspector(*Addr, *IdentityPath)
if err != nil {
return ErrInspectorDial.Wrap(err)
}

defer func() { err = errs.Combine(err, i.Close()) }()

_, err = i.paymentsClient.ApplyInvoiceRecords(context.Background(), &pb.ApplyInvoiceRecordsRequest{})
if err != nil {
return err
}

fmt.Println("successfully created invoice line items")
return nil
}

func createInvoices(cmd *cobra.Command, args []string) error {
i, err := NewInspector(*Addr, *IdentityPath)
if err != nil {
return ErrInspectorDial.Wrap(err)
}

defer func() { err = errs.Combine(err, i.Close()) }()

_, err = i.paymentsClient.CreateInvoices(context.Background(), &pb.CreateInvoicesRequest{})
if err != nil {
return err
}

fmt.Println("successfully created invoices")
return nil
}

// parseDateString parses provided date string and returns corresponding time.Time.
func parseDateString(s string) (time.Time, error) {
values := strings.Split(s, "/")

if len(values) != 2 {
return time.Time{}, errs.New("invalid date format %s, use mm/yyyy", s)
}

month, err := strconv.ParseInt(values[0], 10, 64)
if err != nil {
return time.Time{}, errs.New("can not parse month: %v", err)
}
year, err := strconv.ParseInt(values[1], 10, 64)
if err != nil {
return time.Time{}, errs.New("can not parse year: %v", err)
}

date := time.Date(int(year), time.Month(month), 1, 0, 0, 0, 0, time.UTC)
if date.Year() != int(year) || date.Month() != time.Month(month) || date.Day() != 1 {
return date, errs.New("dates mismatch have %s result %s", s, date)
}

return date, nil
}

func init() {
rootCmd.AddCommand(statsCmd)
rootCmd.AddCommand(irreparableCmd)
rootCmd.AddCommand(healthCmd)
rootCmd.AddCommand(paymentsCmd)

healthCmd.AddCommand(objectHealthCmd)
healthCmd.AddCommand(segmentHealthCmd)

paymentsCmd.AddCommand(prepareInvoiceRecordsCmd)
paymentsCmd.AddCommand(createInvoiceItemsCmd)
paymentsCmd.AddCommand(createInvoicesCmd)

objectHealthCmd.Flags().StringVar(&CSVPath, "csv-path", "stdout", "csv path where command output is written")

irreparableCmd.Flags().Int32Var(&irreparableLimit, "limit", 50, "max number of results per page")
Expand Down
6 changes: 3 additions & 3 deletions installer/windows/Storj/CustomAction.cs
Expand Up @@ -65,13 +65,13 @@ public static ActionResult ValidateWallet(Session session)

if (string.IsNullOrEmpty(wallet))
{
session["STORJ_WALLET_VALID"] = "The wallet address cannot be empty.";
session["STORJ_WALLET_VALID"] = "The payout address cannot be empty.";
return ActionResult.Success;
}

if (!wallet.StartsWith("0x"))
{
session["STORJ_WALLET_VALID"] = "The wallet address must start with a '0x' prefix.";
session["STORJ_WALLET_VALID"] = "The payout address must start with a '0x' prefix.";
return ActionResult.Success;
}

Expand All @@ -80,7 +80,7 @@ public static ActionResult ValidateWallet(Session session)

if (wallet.Length != 40)
{
session["STORJ_WALLET_VALID"] = "The wallet address must have 40 characters after the '0x' prefix.";
session["STORJ_WALLET_VALID"] = "The payout address must have 40 characters after the '0x' prefix.";
return ActionResult.Success;
}

Expand Down
6 changes: 3 additions & 3 deletions installer/windows/WalletConfig.wxs
Expand Up @@ -9,15 +9,15 @@
<Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>
</Control>

<Control Id="Description" Type="Text" X="25" Y="23" Width="280" Height="15" Transparent="yes" NoPrefix="yes" Text="Enter your Ethereum wallet address." />
<Control Id="Description" Type="Text" X="25" Y="23" Width="280" Height="15" Transparent="yes" NoPrefix="yes" Text="Enter your payout address." />
<Control Id="Title" Type="Text" X="15" Y="6" Width="200" Height="15" Transparent="yes" NoPrefix="yes" Text="{\WixUI_Font_Title}Operator Information" />
<Control Id="BannerBitmap" Type="Bitmap" X="0" Y="0" Width="370" Height="44" TabSkip="no" Text="!(loc.InstallDirDlgBannerBitmap)" />
<Control Id="BannerLine" Type="Line" X="0" Y="44" Width="370" Height="0" />
<Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0" />

<Control Id="WalletLabel" Type="Text" X="20" Y="60" Width="320" Height="16" NoPrefix="yes" Text="Ethereum wallet address:" />
<Control Id="WalletLabel" Type="Text" X="20" Y="60" Width="320" Height="16" NoPrefix="yes" Text="STORJ payout address (ERC-20 compatible):" />
<Control Id="Wallet" Type="Edit" Property="STORJ_WALLET" X="20" Y="100" Width="320" Height="18" />
<Control Id="WalletDesc" Type="Text" X="20" Y="150" Width="320" Height="16" NoPrefix="yes" Text="This wallet address will receive the STORJ token payouts for running the storage node." />
<Control Id="WalletDesc" Type="Text" X="20" Y="150" Width="320" Height="16" NoPrefix="yes" Text="This payout address will receive the STORJ token payouts for running the storage node." />
<Control Id="WalletHowto" Type="Hyperlink" X="20" Y="170" Width="320" Height="16">
<Text><![CDATA[<a href="https://support.storj.io/hc/en-us/articles/360026611692">Learn how to obtain a valid payout address.</a>]]></Text>
</Control>
Expand Down

0 comments on commit b5f03e1

Please sign in to comment.