Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Airdrop Getters #19

Merged
merged 10 commits into from
Aug 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions airdrop/getter.gno
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ func GetClaimStatus(jsonStr string, claimID uint64) string {
}

// AirdropToJSON converts an Airdrop struct to a JSON string.
//
// Example:
//
// {
// "config": {
// "refundable_timestamp": "1234567890",
// "refund_to": "g1234567890abcdefghijklmnop"
// },
// "address": "g1234567890abcdefghijklmnop",
// "claimed_bitmap": { // ref: getter_test.gno/TestAirdropToJSONAndCreateAirdropFromJSON
// "0": "101",
// "1": "1101",
// },
// }
func AirdropToJSON(a *Airdrop) string {
r3v4s marked this conversation as resolved.
Show resolved Hide resolved
node := json.ObjectNode("", nil)

Expand Down Expand Up @@ -166,7 +180,7 @@ func createAirdropFromJSON(jsonStr string) *Airdrop {
configNode := node.MustKey("config")

timestamp := configNode.MustKey("refundable_timestamp").MustString()
refundableTimestamp, err := parseUint(timestamp, 10, 64)
refundableTimestamp, err := strconv.Atoi(timestamp)
if err != nil {
panic(err)
}
Expand All @@ -180,20 +194,20 @@ func createAirdropFromJSON(jsonStr string) *Airdrop {
claimedBitmap := make(map[uint64]uint64)

claimedBitmapNode.ObjectEach(func(key string, value *json.Node) {
index, err := parseUint(key, 10, 64)
index, err := strconv.Atoi(key)
if err != nil {
panic(err)
}
bitmap, err := parseUint(value.MustString(), 2, 64)
if err != nil {
panic(err)
}
claimedBitmap[index] = bitmap
claimedBitmap[uint64(index)] = bitmap
})

return &Airdrop{
config: Config{
RefundableTimestamp: refundableTimestamp,
RefundableTimestamp: uint64(refundableTimestamp),
RefundTo: refundTo,
},
address: address,
Expand Down