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

implement suggested params #72

Merged
merged 27 commits into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4521884
enable user to specify fee when getting transactions for the split co…
mjiang102628 Jan 23, 2020
6e00763
Update template.py
mjiang102628 Jan 23, 2020
6e0e021
Update template.py
mjiang102628 Jan 23, 2020
8ad2483
Merge branch 'develop' into michelle/split
mjiang102628 Jan 30, 2020
1345c16
Update test_unit.py
mjiang102628 Jan 30, 2020
3234f89
fix ratio implementation
mjiang102628 Feb 5, 2020
333fa1e
merge from develop
mjiang102628 Feb 5, 2020
b3efcbf
flip order of rat_1 and rat_2, use new golden
mjiang102628 Feb 5, 2020
0121530
add get_transaction for HTLC
mjiang102628 Feb 5, 2020
6930a7e
read receiver from contract in HTLC
mjiang102628 Feb 5, 2020
09ea8d0
Update test_unit.py
mjiang102628 Feb 5, 2020
e6a5f8f
Update test_unit.py
mjiang102628 Feb 5, 2020
f76c971
fix encoding bug
mjiang102628 Feb 5, 2020
2387417
add check for preimage matching hash image
mjiang102628 Feb 7, 2020
4bbf251
Update template.py
mjiang102628 Feb 11, 2020
7d821bb
implement txn params
mjiang102628 Feb 12, 2020
a6155a7
fix checks for override values
mjiang102628 Feb 12, 2020
51fadd3
update docstrings to allow None for params argument
mjiang102628 Feb 12, 2020
7a8984c
add SuggestedParams class
mjiang102628 Feb 19, 2020
f2ae305
Update transaction.py
mjiang102628 Feb 20, 2020
6349ba9
merge from develop
mjiang102628 Feb 20, 2020
5b6dbb6
pep8 compliance and extra check during encoding
mjiang102628 Feb 21, 2020
d6cc1b9
make genesisID optional
mjiang102628 Feb 25, 2020
4c4b487
Update transaction.py
mjiang102628 Feb 25, 2020
351dc48
Update template.py
mjiang102628 Feb 25, 2020
d8988e4
Update algod.py
mjiang102628 Feb 25, 2020
2238c7c
Update test_unit.py
mjiang102628 Feb 26, 2020
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# Changelog
# 2.0.0
# Added
- Added support for Algorand Smart Contracts (ASC)
- Dynamic fee contract
- Limit order contract
- Periodic payment contract

# Changed
- Transactions and templates now take suggested params obtained from algod as an argument; the SuggestedParams object contains fee, first valid round, last valid round, genesis hash, and genesis ID

# 1.1.1
# Added
- Added asset decimals field.
Expand Down
71 changes: 26 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,11 @@ acl = algod.AlgodClient(params.algod_token, params.algod_address)
kcl = kmd.KMDClient(params.kmd_token, params.kmd_address)

# get suggested parameters
params = acl.suggested_params()
gen = params["genesisID"]
gh = params["genesishashb64"]
last_round = params["lastRound"]
fee = params["fee"]
sp = acl.suggested_params()

# create a transaction
amount = 10000
txn = transaction.PaymentTxn(sender, fee, last_round, last_round+100, gh, receiver, amount)
txn = transaction.PaymentTxn(sender, sp, receiver, amount)

# write to file
txns = [txn]
Expand Down Expand Up @@ -180,16 +176,12 @@ threshold = 2 # how many signatures are necessary
msig = transaction.Multisig(version, threshold, [account_1, account_2])

# get suggested parameters
params = acl.suggested_params()
gen = params["genesisID"]
gh = params["genesishashb64"]
last_round = params["lastRound"]
fee = params["fee"]
sp = acl.suggested_params()

# create a transaction
sender = msig.address()
amount = 10000
txn = transaction.PaymentTxn(sender, fee, last_round, last_round+100, gh, account_3, amount)
txn = transaction.PaymentTxn(sender, sp, account_3, amount)

# create a SignedTransaction object
mtx = transaction.MultisigTransaction(txn, msig)
Expand All @@ -216,19 +208,15 @@ acl = algod.AlgodClient("API-TOKEN", "API-Address")
sk = mnemonic.to_private_key(passphrase)

# get suggested parameters
params = acl.suggested_params()
gen = params["genesisID"]
gh = params["genesishashb64"]
last_round = params["lastRound"]
fee = params["fee"]
sp = acl.suggested_params()

# Set other parameters
amount = 100000
note = "Some Text".encode()
receiver = "receiver Algorand Address"

# create the transaction
txn = transaction.PaymentTxn(account.address_from_private_key(sk), fee, last_round, last_round+1000, gh, receiver, amount, note=note)
txn = transaction.PaymentTxn(account.address_from_private_key(sk), sp, receiver, amount, note=note)

# sign it
stx = txn.sign(sk)
Expand Down Expand Up @@ -257,16 +245,12 @@ acl = algod.AlgodClient(params.algod_token, params.algod_address)
kcl = kmd.KMDClient(params.kmd_token, params.kmd_address)

# get suggested parameters
params = acl.suggested_params()
gen = params["genesisID"]
gh = params["genesishashb64"]
last_round = params["lastRound"]
fee = params["fee"]
sp = acl.suggested_params()

# create a transaction
amount = 10000
txn1 = transaction.PaymentTxn(sender, fee, last_round, last_round+100, gh, receiver, amount)
txn2 = transaction.PaymentTxn(receiver, fee, last_round, last_round+100, gh, sender, amount)
txn1 = transaction.PaymentTxn(sender, sp, receiver, amount)
txn2 = transaction.PaymentTxn(receiver, sp, sender, amount)

# get group id and assign it to transactions
gid = transaction.calculate_group_id([txn1, txn2])
Expand Down Expand Up @@ -297,15 +281,11 @@ sender = lsig.address()
acl = algod.AlgodClient(params.algod_token, params.algod_address)

# get suggested parameters
params = acl.suggested_params()
gen = params["genesisID"]
gh = params["genesishashb64"]
last_round = params["lastRound"]
fee = params["fee"]
sp = acl.suggested_params()

# create a transaction
amount = 10000
txn = transaction.PaymentTxn(sender, fee, last_round, last_round+100, gh, receiver, amount)
txn = transaction.PaymentTxn(sender, sp, receiver, amount)

# note, transaction is signed by logic only (no delegation)
# that means sender address must match to program hash
Expand Down Expand Up @@ -341,8 +321,8 @@ metadata = bytes("fACPO4nRgO55j1ndAK3W6Sgc4APkcyFh", "ascii") # should be a 32-b
default_frozen = False # whether accounts should be frozen by default

# create the asset creation transaction
txn = transaction.AssetConfigTxn(address, fee_per_byte, first_valid_round,
last_valid_round, genesis_hash, total=total, manager=manager,
sp = transaction.SuggestedParams(first_valid_round, last_valid_round, genesis_hash, None, fee_per_byte)
txn = transaction.AssetConfigTxn(address, sp, total=total, manager=manager,
reserve=reserve, freeze=freeze, clawback=clawback,
unit_name=unitname, asset_name=assetname, url=url,
metadata_hash=metadata, default_frozen=default_frozen)
Expand Down Expand Up @@ -370,8 +350,8 @@ genesis_hash = "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI="
index = 1234 # identifying index of the asset

# create the asset config transaction
txn = transaction.AssetConfigTxn(manager_address, fee_per_byte, first_valid_round,
last_valid_round, genesis_hash, manager=new_manager, reserve=new_reserve,
sp = transaction.SuggestedParams(first_valid_round, last_valid_round, genesis_hash, None, fee_per_byte)
txn = transaction.AssetConfigTxn(manager_address, sp, manager=new_manager, reserve=new_reserve,
freeze=new_freeze, clawback=new_clawback, index=index)

# sign the transaction
Expand All @@ -394,8 +374,9 @@ genesis_hash = "SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI="
index = 1234 # identifying index of the asset

# create the asset destroy transaction
txn = transaction.AssetConfigTxn(creator_address, fee_per_byte, first_valid_round, last_valid_round, genesis_hash,
index=index, strict_empty_address_check=False)
sp = transaction.SuggestedParams(first_valid_round, last_valid_round, genesis_hash, None, fee_per_byte)
txn = transaction.AssetConfigTxn(creator_address, sp, index=index, strict_empty_address_check=False)

# sign the transaction
signed_txn = txn.sign(creator_private_key)
```
Expand All @@ -417,8 +398,8 @@ freeze_target = "address to be frozen or unfrozen"
index = 1234 # identifying index of the asset

# create the asset freeze transaction
txn = transaction.AssetFreezeTxn(freeze_address, fee_per_byte, first_valid_round,
last_valid_round, genesis_hash, index=index, target=freeze_target,
sp = transaction.SuggestedParams(first_valid_round, last_valid_round, genesis_hash, None, fee_per_byte)
txn = transaction.AssetFreezeTxn(freeze_address, sp, index=index, target=freeze_target,
new_freeze_state=True)

# sign the transaction
Expand All @@ -443,8 +424,8 @@ amount = 100 # amount of assets to transfer
index = 1234 # identifying index of the asset

# create the asset transfer transaction
txn = transaction.AssetTransferTxn(sender_address, fee_per_byte,
first_valid_round, last_valid_round, genesis_hash,
sp = transaction.SuggestedParams(first_valid_round, last_valid_round, genesis_hash, None, fee_per_byte)
txn = transaction.AssetTransferTxn(sender_address, sp,
receiver, amount, index, close_assets_to)

# sign the transaction
Expand All @@ -468,8 +449,8 @@ amount = 0 # to start accepting assets, set amount to 0
index = 1234 # identifying index of the asset

# create the asset accept transaction
txn = transaction.AssetTransferTxn(address, fee_per_byte,
first_valid_round, last_valid_round, genesis_hash,
sp = transaction.SuggestedParams(first_valid_round, last_valid_round, genesis_hash, None, fee_per_byte)
txn = transaction.AssetTransferTxn(address, sp,
receiver, amount, index)

# sign the transaction
Expand All @@ -495,8 +476,8 @@ amount = 100
index = 1234 # identifying index of the asset

# create the asset transfer transaction
txn = transaction.AssetTransferTxn(clawback_address, fee_per_byte,
first_valid_round, last_valid_round, genesis_hash,
sp = transaction.SuggestedParams(first_valid_round, last_valid_round, genesis_hash, None, fee_per_byte)
txn = transaction.AssetTransferTxn(clawback_address, sp,
receiver, amount, index, revocation_target=target)

# sign the transaction
Expand Down
11 changes: 10 additions & 1 deletion algosdk/algod.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from . import error
from . import encoding
from . import constants
from . import transaction


class AlgodClient:
Expand Down Expand Up @@ -225,7 +226,15 @@ def suggested_fee(self, **kwargs):
def suggested_params(self, **kwargs):
"""Return suggested transaction parameters."""
req = "/transactions/params"
return self.algod_request("GET", req, **kwargs)
res = self.algod_request("GET", req, **kwargs)

return transaction.SuggestedParams(
res["lastRound"],
res["lastRound"] + 1000,
res["genesishashb64"],
res["genesisID"],
res["fee"],
False)

def send_raw_transaction(self, txn, **kwargs):
"""
Expand Down
Loading