/
deposit_to_nft.go
84 lines (73 loc) · 2.38 KB
/
deposit_to_nft.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"flag"
"fmt"
"os"
"github.com/mr-tron/base58"
"github.com/iotaledger/goshimmer/client/wallet"
"github.com/iotaledger/goshimmer/client/wallet/packages/deposittonftoptions"
"github.com/iotaledger/goshimmer/packages/core/ledger/vm/devnetvm"
)
func execDepositToNFTCommand(command *flag.FlagSet, cliWallet *wallet.Wallet) {
command.Usage = func() {
printUsage(command)
}
helpPtr := command.Bool("help", false, "show this help screen")
nftIDPtr := command.String("id", "", "unique identifier of the nft to deposit to")
colorPtr := command.String("color", "IOTA", "color of funds to deposit")
amountPtr := command.Int64("amount", 0, "the amount of tokens that are supposed to be deposited")
accessManaPledgeIDPtr := command.String("access-mana-id", "", "node ID to pledge access mana to")
consensusManaPledgeIDPtr := command.String("consensus-mana-id", "", "node ID to pledge consensus mana to")
err := command.Parse(os.Args[2:])
if err != nil {
printUsage(command, err.Error())
}
if *helpPtr {
printUsage(command)
}
if *nftIDPtr == "" {
printUsage(command, "id of the nft to deposit to should be given")
}
if *amountPtr <= 0 {
printUsage(command, "amount has to be set and be bigger than 0")
}
if *colorPtr == "" {
printUsage(command, "color must be set")
}
aliasID, err := devnetvm.AliasAddressFromBase58EncodedString(*nftIDPtr)
if err != nil {
printUsage(command, err.Error())
}
depositBalance := map[devnetvm.Color]uint64{}
if *amountPtr > 0 {
var initColor devnetvm.Color
// get color
switch *colorPtr {
case "IOTA":
initColor = devnetvm.ColorIOTA
case "NEW":
initColor = devnetvm.ColorMint
default:
colorBytes, parseErr := base58.Decode(*colorPtr)
if parseErr != nil {
printUsage(command, parseErr.Error())
}
initColor, _, parseErr = devnetvm.ColorFromBytes(colorBytes)
if parseErr != nil {
printUsage(command, parseErr.Error())
}
}
depositBalance[initColor] = uint64(*amountPtr)
}
fmt.Println("Depositing funds into NFT...")
_, err = cliWallet.DepositFundsToNFT(
deposittonftoptions.Alias(aliasID.Base58()),
deposittonftoptions.Amount(depositBalance),
deposittonftoptions.AccessManaPledgeID(*accessManaPledgeIDPtr),
deposittonftoptions.ConsensusManaPledgeID(*consensusManaPledgeIDPtr),
)
if err != nil {
printUsage(command, err.Error())
}
fmt.Println("Depositing funds into NFT... [DONE]")
}