obsidian
obsidian
AEAsh Elixir
Created by obsidian on 5/31/2023 in #support
Is it possible to pass a map to args instead of a list of attributes in code_interface?
Ok great! Really appreciate the help Zach
28 replies
AEAsh Elixir
Created by obsidian on 5/31/2023 in #support
Is it possible to pass a map to args instead of a list of attributes in code_interface?
Because when I query the wallet again, I get all the updates:
iex(49)> {:ok, [wallet]} = Leaderboard.Data.Wallet.find_wallet("SPAX2SZCDFTVV76SR4JY4RYEPC5PBH2QAHEJXHTF", :stacks)

["SPAX2SZCDFTVV76SR4JY4RYEPC5PBH2QAHEJXHTF", :stacks]
{:ok,
[
#Leaderboard.Data.Wallet<
__meta__: #Ecto.Schema.Metadata<:loaded, "wallets">,
id: "318fd4a8-5a4d-47d5-80c2-613207a3d6fc",
address: "SPAX2SZCDFTVV76SR4JY4RYEPC5PBH2QAHEJXHTF",
chain: :stacks,
bought_usd_volume: 1.0,
bought_volume: 2.0,
holdings_count: 3,
holdings_listed_count: nil,
realized_profit_loss: nil,
realized_usd_profit_loss: nil,
sold_usd_volume: nil,
sold_volume: nil,
unrealized_profit_loss: nil,
unrealized_usd_profit_loss: nil,
usd_value: 2000.0,
value: nil,
timestamp: nil,
block_height: 10,
aggregates: %{},
calculations: %{},
__order__: nil,
...
>
]}
iex(49)> {:ok, [wallet]} = Leaderboard.Data.Wallet.find_wallet("SPAX2SZCDFTVV76SR4JY4RYEPC5PBH2QAHEJXHTF", :stacks)

["SPAX2SZCDFTVV76SR4JY4RYEPC5PBH2QAHEJXHTF", :stacks]
{:ok,
[
#Leaderboard.Data.Wallet<
__meta__: #Ecto.Schema.Metadata<:loaded, "wallets">,
id: "318fd4a8-5a4d-47d5-80c2-613207a3d6fc",
address: "SPAX2SZCDFTVV76SR4JY4RYEPC5PBH2QAHEJXHTF",
chain: :stacks,
bought_usd_volume: 1.0,
bought_volume: 2.0,
holdings_count: 3,
holdings_listed_count: nil,
realized_profit_loss: nil,
realized_usd_profit_loss: nil,
sold_usd_volume: nil,
sold_volume: nil,
unrealized_profit_loss: nil,
unrealized_usd_profit_loss: nil,
usd_value: 2000.0,
value: nil,
timestamp: nil,
block_height: 10,
aggregates: %{},
calculations: %{},
__order__: nil,
...
>
]}
28 replies
AEAsh Elixir
Created by obsidian on 5/31/2023 in #support
Is it possible to pass a map to args instead of a list of attributes in code_interface?
Second update of wallet: Just sets usd_value.
iex(45)> new_stats
%{usd_value: 2000.0}
iex(46)> Leaderboard.Data.Wallet.update_stats(wallet, new_stats)
commit []
{:ok,
#Leaderboard.Data.Wallet<
__meta__: #Ecto.Schema.Metadata<:loaded, "wallets">,
id: "318fd4a8-5a4d-47d5-80c2-613207a3d6fc",
address: "SPAX2SZCDFTVV76SR4JY4RYEPC5PBH2QAHEJXHTF",
chain: :stacks,
bought_usd_volume: nil,
bought_volume: nil,
holdings_count: nil,
holdings_listed_count: nil,
realized_profit_loss: nil,
realized_usd_profit_loss: nil,
sold_usd_volume: nil,
sold_volume: nil,
unrealized_profit_loss: nil,
unrealized_usd_profit_loss: nil,
usd_value: 2000.0,
value: nil,
timestamp: nil,
block_height: 10,
aggregates: %{},
calculations: %{},
__order__: nil,
...
>}
iex(45)> new_stats
%{usd_value: 2000.0}
iex(46)> Leaderboard.Data.Wallet.update_stats(wallet, new_stats)
commit []
{:ok,
#Leaderboard.Data.Wallet<
__meta__: #Ecto.Schema.Metadata<:loaded, "wallets">,
id: "318fd4a8-5a4d-47d5-80c2-613207a3d6fc",
address: "SPAX2SZCDFTVV76SR4JY4RYEPC5PBH2QAHEJXHTF",
chain: :stacks,
bought_usd_volume: nil,
bought_volume: nil,
holdings_count: nil,
holdings_listed_count: nil,
realized_profit_loss: nil,
realized_usd_profit_loss: nil,
sold_usd_volume: nil,
sold_volume: nil,
unrealized_profit_loss: nil,
unrealized_usd_profit_loss: nil,
usd_value: 2000.0,
value: nil,
timestamp: nil,
block_height: 10,
aggregates: %{},
calculations: %{},
__order__: nil,
...
>}
As you can see, the previous bought_usd_volume etc... is now nil. I'm assuming this is because I'm passing in the original wallet before the update. So the logs that I'm seeing are not a return of the wallet object on a round trip from the db. But rather it is just logging what the change will look like
28 replies
AEAsh Elixir
Created by obsidian on 5/31/2023 in #support
Is it possible to pass a map to args instead of a list of attributes in code_interface?
Yea I guess the order is: First update of wallet, setting
bought_usd_volume
bought_usd_volume
bought_volume
bought_volume
```elixir
iex(39)> Leaderboard.Data.Wallet.update_stats(wallet, stats)

commit []
{:ok,
#Leaderboard.Data.Wallet<
__meta__: #Ecto.Schema.Metadata<:loaded, "wallets">,
id: "318fd4a8-5a4d-47d5-80c2-613207a3d6fc",
address: "SPAX2SZCDFTVV76SR4JY4RYEPC5PBH2QAHEJXHTF",
chain: :stacks,
bought_usd_volume: 1.0,
bought_volume: 2.0,
holdings_count: 3,
holdings_listed_count: nil,
realized_profit_loss: nil,
realized_usd_profit_loss: nil,
sold_usd_volume: nil,
sold_volume: nil,
unrealized_profit_loss: nil,
unrealized_usd_profit_loss: nil,
usd_value: nil,
value: nil,
timestamp: nil,
block_height: 10,
aggregates: %{},
calculations: %{},
__order__: nil,
...
>}
```elixir
iex(39)> Leaderboard.Data.Wallet.update_stats(wallet, stats)

commit []
{:ok,
#Leaderboard.Data.Wallet<
__meta__: #Ecto.Schema.Metadata<:loaded, "wallets">,
id: "318fd4a8-5a4d-47d5-80c2-613207a3d6fc",
address: "SPAX2SZCDFTVV76SR4JY4RYEPC5PBH2QAHEJXHTF",
chain: :stacks,
bought_usd_volume: 1.0,
bought_volume: 2.0,
holdings_count: 3,
holdings_listed_count: nil,
realized_profit_loss: nil,
realized_usd_profit_loss: nil,
sold_usd_volume: nil,
sold_volume: nil,
unrealized_profit_loss: nil,
unrealized_usd_profit_loss: nil,
usd_value: nil,
value: nil,
timestamp: nil,
block_height: 10,
aggregates: %{},
calculations: %{},
__order__: nil,
...
>}
28 replies
AEAsh Elixir
Created by obsidian on 5/31/2023 in #support
Is it possible to pass a map to args instead of a list of attributes in code_interface?
So I'm assuming the logs I see here, are not a return of the updated data from the db, but rather just showing what the update will look like?
28 replies
AEAsh Elixir
Created by obsidian on 5/31/2023 in #support
Is it possible to pass a map to args instead of a list of attributes in code_interface?
Hmm I cleared my console, before this. But that's probably it. I'm passing in the original wallet that I queried from the db. So basically I queried
Did this action:
Did this action:
elixir iex(39)> Leaderboard.Data.Wallet.update_stats(wallet, stats) commit [] {:ok, #Leaderboard.Data.Wallet< meta: #Ecto.Schema.Metadata<:loaded, "wallets">, id: "318fd4a8-5a4d-47d5-80c2-613207a3d6fc", address: "SPAX2SZCDFTVV76SR4JY4RYEPC5PBH2QAHEJXHTF", chain: :stacks, bought_usd_volume: 1.0, bought_volume: 2.0, holdings_count: 3, holdings_listed_count: nil, realized_profit_loss: nil, realized_usd_profit_loss: nil, sold_usd_volume: nil, sold_volume: nil, unrealized_profit_loss: nil, unrealized_usd_profit_loss: nil, usd_value: nil, value: nil, timestamp: nil, block_height: 10, aggregates: %{}, calculations: %{}, order: nil, ... >}``` And then the next time I did the update, I passed in the old wallet variable.
28 replies
AEAsh Elixir
Created by obsidian on 5/31/2023 in #support
Is it possible to pass a map to args instead of a list of attributes in code_interface?
Yea you can see the logs here:
iex(45)> new_stats
%{usd_value: 2000.0}
iex(46)> Leaderboard.Data.Wallet.update_stats(wallet, new_stats)
commit []
{:ok,
#Leaderboard.Data.Wallet<
__meta__: #Ecto.Schema.Metadata<:loaded, "wallets">,
id: "318fd4a8-5a4d-47d5-80c2-613207a3d6fc",
address: "SPAX2SZCDFTVV76SR4JY4RYEPC5PBH2QAHEJXHTF",
chain: :stacks,
bought_usd_volume: nil,
bought_volume: nil,
holdings_count: nil,
holdings_listed_count: nil,
realized_profit_loss: nil,
realized_usd_profit_loss: nil,
sold_usd_volume: nil,
sold_volume: nil,
unrealized_profit_loss: nil,
unrealized_usd_profit_loss: nil,
usd_value: 2000.0,
value: nil,
timestamp: nil,
block_height: 10,
aggregates: %{},
calculations: %{},
__order__: nil,
...
>}
iex(47)> new_stats
%{usd_value: 2000.0}

iex(48)> stats2 = %{sold_volume: 1234.5}
%{sold_volume: 1234.5}
iex(49)> {:ok, [wallet]} = Leaderboard.Data.Wallet.find_wallet("SPAX2SZCDFTVV76SR4JY4RYEPC5PBH2QAHEJXHTF", :stacks)

["SPAX2SZCDFTVV76SR4JY4RYEPC5PBH2QAHEJXHTF", :stacks]
{:ok,
[
#Leaderboard.Data.Wallet<
__meta__: #Ecto.Schema.Metadata<:loaded, "wallets">,
id: "318fd4a8-5a4d-47d5-80c2-613207a3d6fc",
address: "SPAX2SZCDFTVV76SR4JY4RYEPC5PBH2QAHEJXHTF",
chain: :stacks,
bought_usd_volume: 1.0,
bought_volume: 2.0,
holdings_count: 3,
holdings_listed_count: nil,
realized_profit_loss: nil,
realized_usd_profit_loss: nil,
sold_usd_volume: nil,
sold_volume: nil,
unrealized_profit_loss: nil,
unrealized_usd_profit_loss: nil,
usd_value: 2000.0,
value: nil,
timestamp: nil,
block_height: 10,
aggregates: %{},
calculations: %{},
__order__: nil,
...
>
]}
iex(45)> new_stats
%{usd_value: 2000.0}
iex(46)> Leaderboard.Data.Wallet.update_stats(wallet, new_stats)
commit []
{:ok,
#Leaderboard.Data.Wallet<
__meta__: #Ecto.Schema.Metadata<:loaded, "wallets">,
id: "318fd4a8-5a4d-47d5-80c2-613207a3d6fc",
address: "SPAX2SZCDFTVV76SR4JY4RYEPC5PBH2QAHEJXHTF",
chain: :stacks,
bought_usd_volume: nil,
bought_volume: nil,
holdings_count: nil,
holdings_listed_count: nil,
realized_profit_loss: nil,
realized_usd_profit_loss: nil,
sold_usd_volume: nil,
sold_volume: nil,
unrealized_profit_loss: nil,
unrealized_usd_profit_loss: nil,
usd_value: 2000.0,
value: nil,
timestamp: nil,
block_height: 10,
aggregates: %{},
calculations: %{},
__order__: nil,
...
>}
iex(47)> new_stats
%{usd_value: 2000.0}

iex(48)> stats2 = %{sold_volume: 1234.5}
%{sold_volume: 1234.5}
iex(49)> {:ok, [wallet]} = Leaderboard.Data.Wallet.find_wallet("SPAX2SZCDFTVV76SR4JY4RYEPC5PBH2QAHEJXHTF", :stacks)

["SPAX2SZCDFTVV76SR4JY4RYEPC5PBH2QAHEJXHTF", :stacks]
{:ok,
[
#Leaderboard.Data.Wallet<
__meta__: #Ecto.Schema.Metadata<:loaded, "wallets">,
id: "318fd4a8-5a4d-47d5-80c2-613207a3d6fc",
address: "SPAX2SZCDFTVV76SR4JY4RYEPC5PBH2QAHEJXHTF",
chain: :stacks,
bought_usd_volume: 1.0,
bought_volume: 2.0,
holdings_count: 3,
holdings_listed_count: nil,
realized_profit_loss: nil,
realized_usd_profit_loss: nil,
sold_usd_volume: nil,
sold_volume: nil,
unrealized_profit_loss: nil,
unrealized_usd_profit_loss: nil,
usd_value: 2000.0,
value: nil,
timestamp: nil,
block_height: 10,
aggregates: %{},
calculations: %{},
__order__: nil,
...
>
]}
28 replies
AEAsh Elixir
Created by obsidian on 5/31/2023 in #support
Is it possible to pass a map to args instead of a list of attributes in code_interface?
False alarm. I passed in to update :value, and the returned wallet had every other attribute set to nil. But in the db, the data was correct.
28 replies
AEAsh Elixir
Created by obsidian on 5/31/2023 in #support
Is it possible to pass a map to args instead of a list of attributes in code_interface?
Hmm... it seems that if I leave an attribute out, all the other attributes are being set to nil. Is that expected?
28 replies
AEAsh Elixir
Created by obsidian on 5/31/2023 in #support
Is it possible to pass a map to args instead of a list of attributes in code_interface?
ha it was that easy... For some reason that didn't come across to me in the action docs https://ash-hq.org/docs/guides/ash/latest/topics/actions Do you know where I can do a deep dive?
28 replies
AEAsh Elixir
Created by obsidian on 5/31/2023 in #support
Is it possible to pass a map to args instead of a list of attributes in code_interface?
28 replies
AEAsh Elixir
Created by obsidian on 5/31/2023 in #support
Is it possible to pass a map to args instead of a list of attributes in code_interface?
this is what the resource attributes look like:
attributes do
uuid_primary_key :id

attribute :address, :string

attribute :chain, :atom

attribute :bought_usd_volume, :float

attribute :bought_volume, :float

attribute :holdings_count, :integer

attribute :holdings_listed_count, :integer

attribute :realized_profit_loss, :float

attribute :realized_usd_profit_loss, :float

attribute :sold_usd_volume, :float

attribute :sold_volume, :float

attribute :unrealized_profit_loss, :float

attribute :unrealized_usd_profit_loss, :float

attribute :usd_value, :float

attribute :value, :float

attribute :timestamp, :utc_datetime

attribute :block_height, :integer
end
attributes do
uuid_primary_key :id

attribute :address, :string

attribute :chain, :atom

attribute :bought_usd_volume, :float

attribute :bought_volume, :float

attribute :holdings_count, :integer

attribute :holdings_listed_count, :integer

attribute :realized_profit_loss, :float

attribute :realized_usd_profit_loss, :float

attribute :sold_usd_volume, :float

attribute :sold_volume, :float

attribute :unrealized_profit_loss, :float

attribute :unrealized_usd_profit_loss, :float

attribute :usd_value, :float

attribute :value, :float

attribute :timestamp, :utc_datetime

attribute :block_height, :integer
end
28 replies
AEAsh Elixir
Created by obsidian on 5/31/2023 in #support
Is there an example of defining a resource that is an external API that you are querying from?
To be more specific: I'm interfacing with an external read-only GraphQL API: https://indexer.xyz/api-explorer In concept I just need to build some helpers functions to interface with the API. Which of course could be done in it's own module outside of Ash. But I'm curious if there is an "Ash" way of doing this.
5 replies
AEAsh Elixir
Created by obsidian on 5/31/2023 in #support
Is there an example of defining a resource that is an external API that you are querying from?
And if so, would you just model the arguments you need to pass in to query the API? or would you also model the response
5 replies
AEAsh Elixir
Created by obsidian on 5/31/2023 in #support
How do I make an attribute on a resource unique?
awesome thanks
6 replies