forked from akash-network/node
/
escrow.go
60 lines (48 loc) · 1.17 KB
/
escrow.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
package v1beta2
import (
"fmt"
"strconv"
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
dtypes "github.com/akash-network/node/x/deployment/types/v1beta2"
etypes "github.com/akash-network/node/x/escrow/types/v1beta2"
)
const (
bidEscrowScope = "bid"
)
func EscrowAccountForBid(id BidID) etypes.AccountID {
return etypes.AccountID{
Scope: bidEscrowScope,
XID: id.String(),
}
}
func EscrowPaymentForLease(id LeaseID) string {
return fmt.Sprintf("%v/%v/%s", id.GSeq, id.OSeq, id.Provider)
}
func LeaseIDFromEscrowAccount(id etypes.AccountID, pid string) (LeaseID, bool) {
did, ok := dtypes.DeploymentIDFromEscrowAccount(id)
if !ok {
return LeaseID{}, false
}
parts := strings.Split(pid, "/")
if len(parts) != 3 {
return LeaseID{}, false
}
gseq, err := strconv.ParseUint(parts[0], 10, 32)
if err != nil {
return LeaseID{}, false
}
oseq, err := strconv.ParseUint(parts[1], 10, 32)
if err != nil {
return LeaseID{}, false
}
owner, err := sdk.AccAddressFromBech32(parts[2])
if err != nil {
return LeaseID{}, false
}
return MakeLeaseID(
MakeBidID(
MakeOrderID(
dtypes.MakeGroupID(
did, uint32(gseq)), uint32(oseq)), owner)), true
}