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

Support Foreign objects as ABI arguments and address ARC-4 changes #251

Merged
merged 45 commits into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
4cab7a8
Start ABI JSON interaction
algochoi Oct 27, 2021
223b05e
Add static annoation
algochoi Oct 27, 2021
bad480d
Fix Method argument parsing
algochoi Oct 27, 2021
3b6f40c
Add ABI Typing to Method arguments
algochoi Oct 29, 2021
7b732a6
Merge remote-tracking branch 'origin/develop' into algochoi/abi-inter…
algochoi Oct 29, 2021
7cf0608
[WIP] Add AtomicTransactionComposer build functions
algochoi Oct 29, 2021
58cef31
[WIP] Sign and send atomic transaction groups
algochoi Nov 1, 2021
43874b2
Add unit tests for object parsing
algochoi Nov 1, 2021
d3fe73d
Clean up method calls
algochoi Nov 3, 2021
c7f4e14
Address PR comments on JSON objects
algochoi Nov 8, 2021
72d172d
Refactor ABI Type to ABIType so it can be exposed to outside world
algochoi Nov 10, 2021
e96b740
Add cucumber steps for ABI tests and update existing implementation s…
algochoi Nov 10, 2021
e052fa7
Refactor TransactionSigner to Abstract class and merge signatures whe…
algochoi Nov 12, 2021
d55f9a6
Update testing to reflect json unit tests and composer tests
algochoi Nov 16, 2021
a748f7b
Formatting and docstring fixes
algochoi Nov 16, 2021
982d519
Add foreign types for method arguments
algochoi Nov 16, 2021
23f63bb
Clean up imports
algochoi Nov 16, 2021
7daa605
Merge branch 'algochoi/abi-interaction' into algochoi/foreign-types
algochoi Nov 16, 2021
f21ec5d
Fix unit test for appId
algochoi Nov 17, 2021
5a6be1c
Merge branch 'algochoi/abi-interaction' into algochoi/foreign-types
algochoi Nov 17, 2021
cfef0a6
Add unit test for foreign array
algochoi Nov 17, 2021
d63b4d1
Refactor some names and add txn as an arg type
algochoi Nov 18, 2021
5c9d28e
Partially address PR comments
algochoi Nov 19, 2021
5e9ab5a
Merge branch 'algochoi/abi-interaction' into algochoi/foreign-types
algochoi Nov 19, 2021
c024249
Fix encoding args for foreign types
algochoi Nov 19, 2021
9fa591a
Add some additional checks for safety
algochoi Nov 19, 2021
351099a
Fix a step so we check for empty string instead of None
algochoi Nov 19, 2021
c5df38c
Correct foreign app and account indices accounting for the implicit a…
algochoi Nov 22, 2021
8f24033
Merge branch 'algochoi/abi-interaction' into algochoi/foreign-types
algochoi Nov 22, 2021
d664879
Merge branch 'develop' into algochoi/foreign-types
algochoi Nov 30, 2021
34c625c
Resolve formatting
algochoi Nov 30, 2021
b29bdaa
Fix unit tests
algochoi Nov 30, 2021
1239547
Fix foreign objects to compact duplicates and special values
algochoi Dec 13, 2021
c218fdf
Refactor foreign objects, transactions, and address some new ABI changes
algochoi Dec 15, 2021
2fbf11a
ABI composer modifications and test updates
algochoi Dec 18, 2021
2503554
Change Interface and Contract to newest ABI changes
algochoi Dec 21, 2021
eed9935
Fix some integration tests for composer
algochoi Dec 21, 2021
00f550b
Fix remaining composer tests
algochoi Dec 21, 2021
0428abe
Formatting changes
algochoi Dec 21, 2021
ad7a483
Fix method json tests
algochoi Dec 22, 2021
fdddcc7
Address PR Comments, clean up and refactor composer and contract
algochoi Dec 28, 2021
8390be2
Create helper function for populating foreign objects
algochoi Dec 28, 2021
9838025
Change type hints on reference and transaction checks
algochoi Dec 28, 2021
909a54d
Add generics and fix dictifying network info
algochoi Dec 28, 2021
90f1daa
Fix step for cucumber test contract parsing
algochoi Dec 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
unit:
behave --tags="@unit.offline or @unit.algod or @unit.indexer or @unit.rekey or @unit.tealsign or @unit.dryrun or @unit.applications or @unit.responses or @unit.transactions or @unit.responses.231 or @unit.feetest or @unit.indexer.logs" test -f progress2
behave --tags="@unit.offline or @unit.algod or @unit.indexer or @unit.rekey or @unit.tealsign or @unit.dryrun or @unit.applications or @unit.responses or @unit.transactions or @unit.transactions.payment or @unit.responses.231 or @unit.feetest or @unit.indexer.logs or @unit.abijson or @unit.atomic_transaction_composer" test -f progress2

integration:
behave --tags="@algod or @assets or @auction or @kmd or @send or @template or @indexer or @indexer.applications or @rekey or @compile or @dryrun or @dryrun.testing or @applications or @applications.verified or @indexer.231" test -f progress2
behave --tags="@algod or @assets or @auction or @kmd or @send or @template or @indexer or @indexer.applications or @rekey or @compile or @dryrun or @dryrun.testing or @applications or @applications.verified or @indexer.231 or @abi" test -f progress2

docker-test:
./run_integration.sh
4 changes: 4 additions & 0 deletions algosdk/abi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from .util import type_from_string
from .uint_type import UintType
from .ufixed_type import UfixedType
from .base_type import ABIType
from .bool_type import BoolType
from .byte_type import ByteType
from .address_type import AddressType
from .string_type import StringType
from .array_dynamic_type import ArrayDynamicType
from .array_static_type import ArrayStaticType
from .tuple_type import TupleType
from .method import Method, Argument, Returns
from .interface import Interface
from .contract import Contract

name = "abi"
4 changes: 2 additions & 2 deletions algosdk/abi/address_type.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from .base_type import Type
from .base_type import ABIType
from .byte_type import ByteType
from .tuple_type import TupleType
from .. import error

from algosdk import encoding


class AddressType(Type):
class AddressType(ABIType):
"""
Represents an Address ABI Type for encoding.
"""
Expand Down
4 changes: 2 additions & 2 deletions algosdk/abi/array_dynamic_type.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from .base_type import ABI_LENGTH_SIZE, Type
from .base_type import ABI_LENGTH_SIZE, ABIType
from .byte_type import ByteType
from .tuple_type import TupleType
from .. import error


class ArrayDynamicType(Type):
class ArrayDynamicType(ABIType):
"""
Represents a ArrayDynamic ABI Type for encoding.

Expand Down
4 changes: 2 additions & 2 deletions algosdk/abi/array_static_type.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import math

from .base_type import Type
from .base_type import ABIType
from .bool_type import BoolType
from .byte_type import ByteType
from .tuple_type import TupleType
from .. import error


class ArrayStaticType(Type):
class ArrayStaticType(ABIType):
"""
Represents a ArrayStatic ABI Type for encoding.

Expand Down
5 changes: 2 additions & 3 deletions algosdk/abi/base_type.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from abc import ABC, abstractmethod
from enum import IntEnum

# Globals
ABI_LENGTH_SIZE = 2 # We use 2 bytes to encode the length of a dynamic element


class Type(ABC):
class ABIType(ABC):
"""
Represents an ABI Type for encoding.
"""
Expand Down Expand Up @@ -45,7 +44,7 @@ def encode(self, value):
pass

@abstractmethod
def decode(self, value_string):
def decode(self, bytestring):
"""
Deserialize the ABI type and value from a byte string using ABI encoding rules.
"""
Expand Down
4 changes: 2 additions & 2 deletions algosdk/abi/bool_type.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from .base_type import Type
from .base_type import ABIType
from .. import error


class BoolType(Type):
class BoolType(ABIType):
"""
Represents a Bool ABI Type for encoding.
"""
Expand Down
4 changes: 2 additions & 2 deletions algosdk/abi/byte_type.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from .base_type import Type
from .base_type import ABIType
from .. import error


class ByteType(Type):
class ByteType(ABIType):
"""
Represents a Byte ABI Type for encoding.
"""
Expand Down
47 changes: 47 additions & 0 deletions algosdk/abi/contract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import json

from algosdk.abi.method import Method


class Contract:
"""
Represents a ABI contract description.

Args:
name (string): name of the contract
app_id (int): application id associated with the contract
methods (list): list of Method objects
"""

def __init__(self, name, app_id, methods) -> None:
self.name = name
self.app_id = int(app_id)
self.methods = methods

def __eq__(self, o: object) -> bool:
if not isinstance(o, Contract):
return False
return (
self.name == o.name
and self.app_id == o.app_id
and self.methods == o.methods
)

@staticmethod
def from_json(resp):
d = json.loads(resp)
return Contract.undictify(d)

def dictify(self):
d = {}
d["name"] = self.name
d["appId"] = self.app_id
d["methods"] = [m.dictify() for m in self.methods]
return d

@staticmethod
def undictify(d):
name = d["name"]
app_id = d["appId"]
method_list = [Method.undictify(method) for method in d["methods"]]
return Contract(name=name, app_id=app_id, methods=method_list)
39 changes: 39 additions & 0 deletions algosdk/abi/interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import json

from algosdk.abi.method import Method


class Interface:
"""
Represents a ABI interface description.

Args:
name (string): name of the interface
methods (list): list of Method objects
"""

def __init__(self, name, methods) -> None:
self.name = name
self.methods = methods

def __eq__(self, o: object) -> bool:
if not isinstance(o, Interface):
return False
return self.name == o.name and self.methods == o.methods

@staticmethod
def from_json(resp):
d = json.loads(resp)
return Interface.undictify(d)

def dictify(self):
d = {}
d["name"] = self.name
d["methods"] = [m.dictify() for m in self.methods]
return d

@staticmethod
def undictify(d):
name = d["name"]
method_list = [Method.undictify(method) for method in d["methods"]]
return Interface(name=name, methods=method_list)
Loading