Skip to content

Commit

Permalink
fix(p/demo/merkle): use constructor & position getter
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaelVallenet committed Sep 12, 2024
1 parent 334bc5d commit 3833126
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 18 deletions.
5 changes: 1 addition & 4 deletions gno/r/launchpad_grc20/airdrop_grc20.gno
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ func ClaimJSON(airdropID uint64, proofsJSON string) {
if err != nil {
panic("invalid hex encoded hash")
}
node := merkle.Node{
Hash: data,
Position: jsonutil.MustUint8(obj["pos"]),
}
node := merkle.NewNode(data, jsonutil.MustUint8(obj["pos"]))
proofs = append(proofs, node)
}
Claim(airdropID, proofs)
Expand Down
2 changes: 1 addition & 1 deletion gno/r/launchpad_grc20/airdrop_grc20_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func TestClaimJSON(t *testing.T) {

proofsJSON := "["
for i, proof := range proofs {
proofsJSON += fmt.Sprintf("{\"hash\":\"%s\", \"pos\":\"%s\"}", proof.GetHexEncodedHash(), strconv.Itoa(int(proof.Position)))
proofsJSON += fmt.Sprintf("{\"hash\":\"%s\", \"pos\":\"%s\"}", proof.Hash(), strconv.Itoa(int(proof.Position())))
if i != len(proofs)-1 {
proofsJSON += ", "
}
Expand Down
15 changes: 7 additions & 8 deletions gno/r/launchpad_grc20/render.gno
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func renderTokenDetailPage(res *mux.ResponseWriter, req *mux.Request) {
res.Write("## List of Airdrops\n")
for _, id := range token.AirdropsIDs {
airdrop := mustGetAirdrop(uint64(id))
res.Write(ufmt.Sprintf("### Airdrop #%d\n", id))
res.Write(ufmt.Sprintf("### Airdrop #%d\n", uint64(id)))
res.Write(ufmt.Sprintf("#### Merkle Root: %s\n", airdrop.merkleRoot))
if airdrop.startTimestamp > 0 {
res.Write(ufmt.Sprintf("#### Start Date: %s\n", time.Unix(airdrop.startTimestamp, 0).Format("2006-01-02 15:04:05")))
Expand All @@ -100,19 +100,19 @@ func renderTokenDetailPage(res *mux.ResponseWriter, req *mux.Request) {
}
res.Write(ufmt.Sprintf("#### Amount to claim per address: %d\n", airdrop.amountPerAddr))
res.Write(ufmt.Sprintf("#### Total addresses claimed: %d\n\n", airdrop.alreadyClaimed.Size()))
res.Write(ufmt.Sprintf("> Link: [:airdrop/%d](launchpad_grc20:airdrop/%d)\n\n", token.AirdropsIDs, token.AirdropsIDs))
res.Write(ufmt.Sprintf("> Link: [:airdrop/%d](../launchpad_grc20:airdrop/%d)\n\n", uint64(id), uint64(id)))
}

res.Write("## List of Sales\n")
for _, id := range token.SalesIDs {
sale := mustGetSale(uint64(id))
res.Write(ufmt.Sprintf("### Sale #%d\n", id))
res.Write(ufmt.Sprintf("### Sale #%d\n", uint64(id)))
res.Write(ufmt.Sprintf("#### Price per token: %d $GNOT\n", sale.pricePerToken))
res.Write(ufmt.Sprintf("#### Limit per address: %d $%s\n", sale.limitPerAddr, token.banker.GetSymbol()))
res.Write(ufmt.Sprintf("#### Min goal: %d $GNOT\n", sale.minGoal))
res.Write(ufmt.Sprintf("#### Max goal: %d $GNOT\n", sale.maxGoal))
res.Write(ufmt.Sprintf("#### Already sold: %d $GNOT\n\n", sale.alreadySold))
res.Write(ufmt.Sprintf("> Link: [:sale/%d](launchpad_grc20:sale/%d)\n\n", token.SalesIDs, token.SalesIDs))
res.Write(ufmt.Sprintf("> Link: [:sale/%d](../launchpad_grc20:sale/%d)\n\n", uint64(id), uint64(id)))
}
renderFooter(res, "../")
}
Expand All @@ -125,7 +125,7 @@ func renderTokenBalancePage(res *mux.ResponseWriter, req *mux.Request) {

res.Write("# 🪙 Token Balance 🪙\n")
res.Write(ufmt.Sprintf("### 📍 Address: %s\n ### 🏦 Balance: %d %s\n", address, balance, token.banker.GetSymbol()))
renderFooter(res, "../../")
renderFooter(res, "../../../")
}

func renderAirdropPage(res *mux.ResponseWriter, req *mux.Request) {
Expand Down Expand Up @@ -211,11 +211,10 @@ func renderAirdropClaimCheckPage(res *mux.ResponseWriter, req *mux.Request) {
res.Write(ufmt.Sprintf("### Amount to claim: %d\n", airdrop.amountPerAddr))
if airdrop.hasAlreadyClaimed(std.Address(address)) {
res.Write("### Address already claimed\n")
return
} else {
res.Write("### Address not yet claimed or not eligible\n")
}
renderFooter(res, "../")
renderFooter(res, "../../../")
}

func renderSalePage(res *mux.ResponseWriter, req *mux.Request) {
Expand Down Expand Up @@ -317,7 +316,7 @@ func renderSaleBalancePage(res *mux.ResponseWriter, req *mux.Request) {
res.Write(ufmt.Sprintf("### 📍 Address: %s\n ### 🏦 Balance (Tokens from this sale only): %d %s\n", address, balance, sale.token.banker.GetSymbol()))

res.Write("> ⚠️ *The tokens will be transfered or refunded after the sale ends depending if the sale reached the min goal or not* ⚠️\n")
renderFooter(res, "../../")
renderFooter(res, "../../../")
}

func renderHomePage(res *mux.ResponseWriter, req *mux.Request) {
Expand Down
6 changes: 2 additions & 4 deletions gno/r/launchpad_grc20/sale_grc20.gno
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var (

func init() {
sales = avl.NewTree()
nextSaleID = seqid.ID(0)
}

func NewSale(tokenName, merkleRoot string, startTimestamp, endTimestamp int64, pricePerToken, limitPerAddr, minGoal, maxGoal uint64, mintToken bool) uint64 {
Expand Down Expand Up @@ -112,10 +113,7 @@ func BuyJSON(saleID, amount uint64, proofsJSON string) {
if err != nil {
panic("invalid hex encoded hash")
}
node := merkle.Node{
Hash: data,
Position: jsonutil.MustUint8(obj["pos"]),
}
node := merkle.NewNode(data, jsonutil.MustUint8(obj["pos"]))
proofs = append(proofs, node)
}
Buy(saleID, amount, proofs)
Expand Down
2 changes: 1 addition & 1 deletion gno/r/launchpad_grc20/token_factory_grc20.gno
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var _ grc20.Token = (*Token)(nil)
var lastTokensIDcreated = []string{}

var (
tokens *avl.Tree // symbol -> token
tokens *avl.Tree // name -> token
factoryAdmin *ownable.Ownable
factoryVault std.Address
)
Expand Down

0 comments on commit 3833126

Please sign in to comment.