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

Codec & serializer - initial implementation #32

Closed
wants to merge 62 commits into from
Closed

Conversation

andreibancioiu
Copy link
Contributor

@andreibancioiu andreibancioiu commented Apr 24, 2024

As seen here (Go):

Reference:

Examples (transactions)

abi = Abi.load(testdata / "multisig-full.abi.json")
config = TransactionsFactoryConfig("D")
factory = SmartContractTransactionsFactory(config, abi)

# All arguments untyped (multisig propose batch)
transaction = factory.create_transaction_for_execute(
    ...
    function="proposeBatch",
    arguments=[
        [
            {
                "__discriminant__": 5,
                "0": {
                    "to": alice,
                    "egld_amount": 1000000000000000000,
                    "endpoint_name": "example",
                    "arguments": [
                        bytes([0x03, 0x42]),
                        bytes([0x07, 0x43])
                    ],
                    "opt_gas_limit": 15_000_000
                }
            }
        ]
    ]
)

# All arguments typed (multisig propose batch)
transaction= factory.create_transaction_for_execute(
    ...
    function="proposeBatch",
    arguments=[
        VariadicValues(
        [
            EnumValue(
                discriminant=5,
                fields=[
                    Field("0", StructValue([
                        Field("to", AddressValue.from_address(alice)),
                        Field("egld_amount", BigUIntValue(1000000000000000000)),
                        Field("opt_gas_limit", OptionValue(U64Value(15_000_000))),
                        Field("endpoint_name", BytesValue(b"example")),
                        Field("arguments", ListValue([
                            BytesValue(bytes([0x03, 0x42])),
                            BytesValue(bytes([0x07, 0x43])),
                        ])),
                    ])),
                ],
            )
        ])
    ]
)

Examples (queries)

abi = Abi.load(self.testdata / "lottery-esdt.abi.json")
query_runner = QueryRunnerAdapter(ApiNetworkProvider("https://devnet-api.multiversx.com"))
controller = SmartContractQueriesController(query_runner, abi)

[lottery_info] = controller.query(
    ...
    function="getLotteryInfo",
    arguments=["myLottery"]
)

assert lottery_info.token_identifier == "lucky-token"
assert lottery_info.ticket_price == 1
assert lottery_info.tickets_left == 0
assert lottery_info.deadline == 0x000000005fc2b9db
assert lottery_info.max_entries_per_user == 0xffffffff
assert lottery_info.prize_distribution == bytes([0x64])
assert lottery_info.prize_pool == 94720000000000000000000

@andreibancioiu andreibancioiu changed the title Sketch (initial commit). Codec & serializer - initial implementation Apr 24, 2024
@andreibancioiu andreibancioiu self-assigned this Apr 24, 2024
Copy link

github-actions bot commented May 16, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  multiversx_sdk/abi
  abi.py 74, 94, 141, 166, 174
  abi_definition.py 19, 47, 70, 90, 110, 118-120, 124, 131, 138-139, 143-145, 151, 184, 207, 251
  address_value.py 16, 32, 39-40, 44, 53
  biguint_value.py 29, 35
  bool_value.py 13-17, 20-21, 26-27, 30-38, 41-47, 50, 53, 56, 59
  bytes_value.py 27, 39
  codec.py 13-15, 23-28
  enum_value.py 32, 38, 48-53, 57, 62, 69-79, 92
  fields.py 19, 26-27, 34-35, 41, 47-48, 52-61
  interface.py 7, 10, 16, 19, 22, 25
  list_value.py 21, 31-35, 43, 51, 66
  option_value.py 16-17, 23-27, 31, 37-38, 44, 47-61, 65-66, 69, 79, 84
  parts.py 29, 34, 49, 58
  serializer.py 16, 33, 87, 95
  shared.py 21, 25, 38-44, 50-54
  small_int_values.py 23, 54-55, 58-59, 62-69, 72-73, 76-82, 85, 88, 91, 123, 128, 131, 136, 139, 144, 147, 152, 155
  string_value.py 19, 27, 30-33, 39, 42
  struct_value.py 21, 36-41, 52
  token_identifier_value.py 13
  tuple_value.py 13-17, 20, 23-27, 30-31, 34-44, 47-48, 51
  type_formula_parser.py 27, 33, 35, 45, 82, 95
  values_multi.py 11-17, 20, 26, 38, 53, 68-79, 82-85
  multiversx_sdk/core
  smart_contract_queries_controller.py 19, 22, 84
  smart_contract_query.py 20, 39-42
  multiversx_sdk/core/transactions_factories
  smart_contract_transactions_factory.py 32, 35, 38
Project Total  

The report is truncated to 25 files out of 31. To see the full report, please visit the workflow summary page.

This report was generated by python-coverage-comment-action

@andreibancioiu
Copy link
Contributor Author

See #52.

@andreibancioiu andreibancioiu deleted the codecs-init branch June 17, 2024 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant