Last active
June 3, 2023 09:47
-
-
Save leeduckgo/707eb037b11d3786680c621aaadc018d to your computer and use it in GitHub Desktop.
CodesOnChain.MoveCrowdfund
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule CodesOnChain.MoveCrowdfund do | |
@moduledoc """ | |
Weightlight backend for MoveCrowdfund. | |
""" | |
alias Web3SuiEx.Sui | |
@network "https://fullnode.testnet.sui.io:443" | |
@move_crowdfund_contract "0x928530ad292091fde082959ca7131f8b0f6209f8faf1a3fe8dc5ca86b2583acf" | |
@shared_fund_info "0x807b26a94f540b4164f5dd03acfb1fecf0c996db627945da4b2cd09ec3014a07" | |
def get_module_doc(), do: @moduledoc | |
def connect() do | |
Sui.RPC.connect(@network) | |
end | |
def get_all_crowdfund_index() do | |
{:ok, client} = connect() | |
Sui.get_object(client, @shared_fund_info) | |
end | |
def get_crowdfund(object_id) do | |
{:ok, client} = connect() | |
Sui.get_object(client, object_id) | |
end | |
def get_all_crowdfund() do | |
{:ok, res} = get_all_crowdfund_index() | |
total_index = res.data.content.fields.total.fields.contents | |
opened_index = res.data.content.fields.open.fields.contents | |
# %{ | |
# opened: opened_index, | |
# total: total_index | |
# } | |
%{ | |
opened: expand_objects(opened_index), | |
total: expand_objects(total_index) | |
} | |
end | |
def expand_objects(obj_index) do | |
{:ok, client} = connect() | |
Enum.map(obj_index, fn obj -> | |
{:ok, res} = Sui.get_object(client, obj) | |
res.data.content.fields | |
end) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment