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

SC new Chain functions #1281

Merged
merged 8 commits into from
Oct 3, 2023
Merged

Conversation

Neylix
Copy link
Member

@Neylix Neylix commented Sep 20, 2023

Description

Add new functions in Chain module:

  • get_previous_address => return the previous address from previous public key or a transaction
  • get_balance => return a map containing the balance of uco and tokens
  • get_uco_balance => return the amount of uco
  • get_token_balance => return the amount of token
  • get_tokens_balance => return a map of token as for the get_balance but only with selected tokens

balance returns a map as

[
  uco: 1234,
  tokens: [
    [token_address: "1234", token_id: 0]: 1234,
    [token_address: "123456", token_id: 1]: 1,
  ]
]

It can be used like this

    balance = Chain.get_balance(previous_address)
    token = [
      token_address: 0x000123...,
      token_id: 0
    ]

    token_balance = Map.get(balance.tokens, token, 0)
    token_balance >= amount

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Unit test and tested with real bridge smart contract

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@Neylix Neylix added feature New feature request smart contracts Involve smart contracts labels Sep 20, 2023
@Neylix Neylix changed the title SC functions: Chain.get_previous_address and Chain.get_balance SC new Chain functions Sep 21, 2023
Copy link
Member

@bchamagne bchamagne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ChainImpl.get_tokens_balance("000030831178cd6a49fe446778455a7a980729a293bfa16b0a1d2743935db210da76" |> String.upcase(), [%{"token_address" => "000058C44C933FBD047BF694490371BB41DA037597FFD57970A1DE6832AF990B7752", "token_id" => 1}])

I expected it to return

%{
  %{
    "token_address" => "000058C44C933FBD047BF694490371BB41DA037597FFD57970A1DE6832AF990B7752",
    "token_id" => 1
  } => 0.0
}

insted of
%{}

@Neylix
Copy link
Member Author

Neylix commented Sep 26, 2023

ChainImpl.get_tokens_balance("000030831178cd6a49fe446778455a7a980729a293bfa16b0a1d2743935db210da76" |> String.upcase(), [%{"token_address" => "000058C44C933FBD047BF694490371BB41DA037597FFD57970A1DE6832AF990B7752", "token_id" => 1}])

I expected it to return

%{
  %{
    "token_address" => "000058C44C933FBD047BF694490371BB41DA037597FFD57970A1DE6832AF990B7752",
    "token_id" => 1
  } => 0.0
}

insted of %{}

Done !

@Neylix Neylix added this to the 1.3.1 milestone Sep 28, 2023
@Neylix Neylix merged commit 24e0355 into archethic-foundation:develop Oct 3, 2023
2 checks passed
@Neylix Neylix deleted the Chain.functions branch October 3, 2023 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request smart contracts Involve smart contracts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants