-
Notifications
You must be signed in to change notification settings - Fork 2
/
txs.go
55 lines (45 loc) · 1.44 KB
/
txs.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
package storage_handler
import (
"fmt"
"github.com/JackalLabs/jackalgo/utils"
"github.com/cosmos/cosmos-sdk/types"
storagetypes "github.com/jackalLabs/canine-chain/v3/x/storage/types"
)
func (s *StorageHandler) BuyStorage(forAddress string, duration int64, gb int64) (*types.TxResponse, error) {
if duration <= 0 {
return nil, fmt.Errorf("cannot use less than 0 months of duration")
}
monthsAsHours := duration * 720
_, err := types.AccAddressFromBech32(forAddress)
if err != nil {
return nil, err
}
buyMsg := storagetypes.MsgBuyStorage{
Creator: s.walletHandler.GetAddress(),
PaymentDenom: "ujkl",
ForAddress: forAddress,
Duration: fmt.Sprintf("%dh", monthsAsHours),
Bytes: fmt.Sprintf("%d", utils.NumTo3xGB(gb)),
}
res, err := s.walletHandler.SendTx(&buyMsg)
return res, err
}
func (s *StorageHandler) UpgradeStorage(forAddress string, duration int64, gb int64) (*types.TxResponse, error) {
if duration <= 0 {
return nil, fmt.Errorf("cannot use less than 0 months of duration")
}
monthsAsHours := duration * 720
_, err := types.AccAddressFromBech32(forAddress)
if err != nil {
return nil, err
}
buyMsg := storagetypes.MsgUpgradeStorage{
Creator: s.walletHandler.GetAddress(),
PaymentDenom: "ujkl",
ForAddress: forAddress,
Duration: fmt.Sprintf("%dh", monthsAsHours),
Bytes: fmt.Sprintf("%d", utils.NumTo3xGB(gb)),
}
res, err := s.walletHandler.SendTx(&buyMsg)
return res, err
}