forked from eoscanada/eosc
/
systemBuyRamBytes.go
41 lines (32 loc) · 1001 Bytes
/
systemBuyRamBytes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright © 2018 EOS Canada <info@eoscanada.com>
package cmd
import (
"context"
"fmt"
"strconv"
"os"
"github.com/sebastianmontero/eos-go/system"
"github.com/spf13/cobra"
)
var systemBuyRAMBytesCmd = &cobra.Command{
Use: "buyrambytes [payer] [receiver] [num bytes]",
Short: "Buy RAM at market price, for a given number of bytes.",
Args: cobra.ExactArgs(3),
Run: func(cmd *cobra.Command, args []string) {
api := getAPI()
payer := toAccount(args[0], "payer")
receiver := toAccount(args[1], "receiver")
numBytes, err := strconv.ParseInt(args[2], 10, 64)
errorCheck(fmt.Sprintf("invalid number of bytes %q", args[2]), err)
if int64(uint32(numBytes)) != numBytes {
fmt.Printf("Invalid number of bytes: capped at unsigned 32 bits. That's probably too much RAM anyway.\n")
os.Exit(1)
}
pushEOSCActions(context.Background(), api,
system.NewBuyRAMBytes(payer, receiver, uint32(numBytes)),
)
},
}
func init() {
systemCmd.AddCommand(systemBuyRAMBytesCmd)
}