-
Notifications
You must be signed in to change notification settings - Fork 0
/
edition_drop_claim_conditions.go
161 lines (141 loc) · 4.33 KB
/
edition_drop_claim_conditions.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package web3sdkio
import (
"context"
"encoding/json"
"math/big"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/web3sdkio/go-sdk/v2/abi"
)
// This interface is currently accessible from the Edition Drop contract contract type
// via the ClaimConditions property.
type EditionDropClaimConditions struct {
abi *abi.DropERC1155
helper *contractHelper
storage storage
}
func newEditionDropClaimConditions(address common.Address, provider *ethclient.Client, helper *contractHelper, storage storage) (*EditionDropClaimConditions, error) {
if contractAbi, err := abi.NewDropERC1155(address, provider); err != nil {
return nil, err
} else {
claimConditions := &EditionDropClaimConditions{
contractAbi,
helper,
storage,
}
return claimConditions, err
}
}
// Get the currently active claim condition for a given token
//
// tokenId: the token ID of the token to get the active claim condition for
//
// returns: the currently active claim condition metadata
//
// Example
//
// tokenId := 0
// condition, err := contract.ClaimConditions.GetActive(context.Background(), tokenId)
//
// // Now you have access to all the claim condition metadata
// fmt.Println("Start Time:", condition.StartTime)
// fmt.Println("Available:", condition.AvailableSupply)
// fmt.Println("Quantity:", condition.MaxQuantity)
// fmt.Println("Quantity Limit:", condition.QuantityLimitPerTransaction)
// fmt.Println("Price:", condition.Price)
// fmt.Println("Wait In Seconds", condition.WaitInSeconds)
func (claim *EditionDropClaimConditions) GetActive(ctx context.Context, tokenId int) (*ClaimConditionOutput, error) {
id, err := claim.abi.GetActiveClaimConditionId(&bind.CallOpts{}, big.NewInt(int64(tokenId)))
if err != nil {
return nil, err
}
mc, err := claim.abi.GetClaimConditionById(&bind.CallOpts{}, big.NewInt(int64(tokenId)), id)
if err != nil {
return nil, err
}
merkle, err := claim.GetMerkleMetadata()
if err != nil {
return nil, err
}
provider := claim.helper.GetProvider()
claimCondition, err := transformResultToClaimCondition(
ctx,
&mc,
merkle,
provider,
claim.storage,
)
if err != nil {
return nil, err
}
return claimCondition, nil
}
// Get all claim conditions on this contract for a given token
//
// tokenId: the token ID of the token to get the claim conditions for
//
// returns: the metadata for all the claim conditions on this contract
//
// Example
//
// tokenId := 0
// conditions, err := contract.ClaimConditions.GetAll(context.Background(), tokenId)
//
// // Now you have access to all the claim condition metadata
// condition := conditions[0]
// fmt.Println("Start Time:", condition.StartTime)
// fmt.Println("Available:", condition.AvailableSupply)
// fmt.Println("Quantity:", condition.MaxQuantity)
// fmt.Println("Quantity Limit:", condition.QuantityLimitPerTransaction)
// fmt.Println("Price:", condition.Price)
// fmt.Println("Wait In Seconds", condition.WaitInSeconds)
func (claim *EditionDropClaimConditions) GetAll(ctx context.Context, tokenId int) ([]*ClaimConditionOutput, error) {
condition, err := claim.abi.ClaimCondition(&bind.CallOpts{Context: ctx}, big.NewInt(int64(tokenId)))
if err != nil {
return nil, err
}
provider := claim.helper.GetProvider()
startId := condition.CurrentStartId.Int64()
count := condition.Count.Int64()
conditions := []*ClaimConditionOutput{}
for i := startId; i < count; i++ {
mc, err := claim.abi.GetClaimConditionById(&bind.CallOpts{}, big.NewInt(int64(tokenId)), big.NewInt(i))
if err != nil {
return nil, err
}
merkle, err := claim.GetMerkleMetadata()
if err != nil {
return nil, err
}
claimCondition, err := transformResultToClaimCondition(
ctx,
&mc,
merkle,
provider,
claim.storage,
)
if err != nil {
return nil, err
}
conditions = append(conditions, claimCondition)
}
return conditions, nil
}
func (claim *EditionDropClaimConditions) GetMerkleMetadata() (*map[string]string, error) {
uri, err := claim.abi.InternalContractURI(&bind.CallOpts{});
if err != nil {
return nil, err
}
body, err := claim.storage.Get(uri);
if err != nil {
return nil, err
}
var rawMetadata struct {
Merkle map[string]string `json:"merkle"`
};
if err := json.Unmarshal(body, &rawMetadata); err != nil {
return nil, err
}
return &rawMetadata.Merkle, nil;
}