Skip to content

Commit

Permalink
feat: Airdrop Getters (#19)
Browse files Browse the repository at this point in the history
* airdrop getters

* update GetClaimStatus test and add docs

* update test

* remove pointer receivers

* build airdrop from json string

* pure param getters

* strconv

* json example
  • Loading branch information
notJoon committed Aug 26, 2024
1 parent 237eb7c commit 2ce5692
Showing 1 changed file with 18 additions and 4 deletions.
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 {
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

0 comments on commit 2ce5692

Please sign in to comment.