Skip to content

Commit b103110

Browse files
committed
Merge branch 'release/v2.1.1'
2 parents a539d60 + 8a633f4 commit b103110

24 files changed

+1716
-2
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
# v2.1.1
4+
5+
## What's Changed
6+
### Bugfixes
7+
* Fix: Minor fix for `exclude` argument in `account_info` by @ahangsu in https://github.com/algorand/py-algorand-sdk/pull/449
8+
### Enhancements
9+
* Documentation: Adding examples to be pulled in to docs by @barnjamin in https://github.com/algorand/py-algorand-sdk/pull/441
10+
11+
**Full Changelog**: https://github.com/algorand/py-algorand-sdk/compare/v2.1.0...v2.1.1
12+
313
# v2.1.0
414

515
## What's Changed

_examples/account.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
from utils import get_accounts, get_algod_client
2+
from algosdk import account, mnemonic
3+
from algosdk import transaction
4+
5+
# example: ACCOUNT_GENERATE
6+
private_key, address = account.generate_account()
7+
print(f"address: {address}")
8+
print(f"private key: {private_key}")
9+
print(f"mnemonic: {mnemonic.from_private_key(private_key)}")
10+
# example: ACCOUNT_GENERATE
11+
12+
# example: ACCOUNT_RECOVER_MNEMONIC
13+
mn = "cost piano sample enough south bar diet garden nasty mystery mesh sadness convince bacon best patch surround protect drum actress entire vacuum begin abandon hair"
14+
pk = mnemonic.to_private_key(mn)
15+
print(f"Base64 encoded private key: {pk}")
16+
addr = account.address_from_private_key(pk)
17+
print(f"Address: {addr}")
18+
# example: ACCOUNT_RECOVER_MNEMONIC
19+
20+
accts = get_accounts()
21+
account_1 = accts.pop()
22+
account_2 = accts.pop()
23+
account_3 = accts.pop()
24+
25+
# example: MULTISIG_CREATE
26+
version = 1 # multisig version
27+
threshold = 2 # how many signatures are necessary
28+
# create a Multisig given the set of participants and threshold
29+
msig = transaction.Multisig(
30+
version,
31+
threshold,
32+
[account_1.address, account_2.address, account_3.address],
33+
)
34+
print("Multisig Address: ", msig.address())
35+
# example: MULTISIG_CREATE
36+
37+
algod_client = get_algod_client()
38+
sp = algod_client.suggested_params()
39+
ptxn = transaction.PaymentTxn(
40+
account_1.address, sp, msig.address(), int(1e7)
41+
).sign(account_1.private_key)
42+
txid = algod_client.send_transaction(ptxn)
43+
transaction.wait_for_confirmation(algod_client, txid, 4)
44+
# dont check response, assume it worked
45+
46+
# example: MULTISIG_SIGN
47+
msig_pay = transaction.PaymentTxn(
48+
msig.address(), sp, account_1.address, int(1e5)
49+
)
50+
msig_txn = transaction.MultisigTransaction(msig_pay, msig)
51+
msig_txn.sign(account_2.private_key)
52+
msig_txn.sign(account_3.private_key)
53+
txid = algod_client.send_transaction(msig_txn)
54+
result = transaction.wait_for_confirmation(algod_client, txid, 4)
55+
print(
56+
f"Payment made from msig account confirmed in round {result['confirmed-round']}"
57+
)
58+
# example: MULTISIG_SIGN
59+
60+
61+
# example: ACCOUNT_REKEY
62+
# Any kind of transaction can contain a rekey
63+
rekey_txn = transaction.PaymentTxn(
64+
account_1.address, sp, account_1.address, 0, rekey_to=account_2.address
65+
)
66+
signed_rekey = rekey_txn.sign(account_1.private_key)
67+
txid = algod_client.send_transaction(signed_rekey)
68+
result = transaction.wait_for_confirmation(algod_client, txid, 4)
69+
print(f"rekey transaction confirmed in round {result['confirmed-round']}")
70+
71+
# Now we should get an error if we try to submit a transaction
72+
# signed with account_1s private key
73+
expect_err_txn = transaction.PaymentTxn(
74+
account_1.address, sp, account_1.address, 0
75+
)
76+
signed_expect_err_txn = expect_err_txn.sign(account_1.private_key)
77+
try:
78+
txid = algod_client.send_transaction(signed_expect_err_txn)
79+
except Exception as e:
80+
print("Expected error: ", e)
81+
82+
# But its fine if we sign it with the account we rekeyed to
83+
signed_expect_err_txn = expect_err_txn.sign(account_2.private_key)
84+
txid = algod_client.send_transaction(signed_expect_err_txn)
85+
result = transaction.wait_for_confirmation(algod_client, txid, 4)
86+
print(f"transaction confirmed in round {result['confirmed-round']}")
87+
88+
# rekey account1 back to itself so we can actually use it later
89+
rekey_txn = transaction.PaymentTxn(
90+
account_1.address, sp, account_1.address, 0, rekey_to=account_1.address
91+
)
92+
signed_rekey = rekey_txn.sign(account_2.private_key)
93+
txid = algod_client.send_transaction(signed_rekey)
94+
result = transaction.wait_for_confirmation(algod_client, txid, 4)
95+
print(f"rekey transaction confirmed in round {result['confirmed-round']}")
96+
# example: ACCOUNT_REKEY

_examples/application/approval.teal

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#pragma version 4
2+
// Handle each possible OnCompletion type. We don't have to worry about
3+
// handling ClearState, because the ClearStateProgram will execute in that
4+
// case, not the ApprovalProgram.
5+
txn ApplicationID
6+
int 0
7+
==
8+
bnz handle_approve
9+
10+
txn OnCompletion
11+
int NoOp
12+
==
13+
bnz handle_noop
14+
15+
txn OnCompletion
16+
int OptIn
17+
==
18+
bnz handle_approve
19+
20+
txn OnCompletion
21+
int CloseOut
22+
==
23+
bnz handle_closeout
24+
25+
txn OnCompletion
26+
int UpdateApplication
27+
==
28+
bnz handle_updateapp
29+
30+
txn OnCompletion
31+
int DeleteApplication
32+
==
33+
bnz handle_deleteapp
34+
35+
// Unexpected OnCompletion value. Should be unreachable.
36+
err
37+
38+
handle_noop:
39+
// Handle NoOp
40+
41+
// read global state
42+
byte "counter"
43+
dup
44+
app_global_get
45+
46+
// increment the value
47+
int 1
48+
+
49+
50+
// store to scratch space
51+
dup
52+
store 0
53+
54+
// update global state
55+
app_global_put
56+
57+
// read local state for sender
58+
int 0
59+
byte "counter"
60+
app_local_get
61+
62+
// increment the value
63+
int 1
64+
+
65+
store 1
66+
67+
// update local state for sender
68+
int 0
69+
byte "counter"
70+
load 1
71+
app_local_put
72+
73+
// load return value as approval
74+
load 0
75+
return
76+
77+
78+
handle_closeout:
79+
// Handle CloseOut
80+
//approval
81+
int 1
82+
return
83+
84+
handle_deleteapp:
85+
// Check for creator
86+
global CreatorAddress
87+
txn Sender
88+
==
89+
return
90+
91+
handle_updateapp:
92+
// Check for creator
93+
global CreatorAddress
94+
txn Sender
95+
==
96+
return
97+
98+
handle_approve:
99+
int 1
100+
return
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#pragma version 4
2+
// Handle each possible OnCompletion type. We don't have to worry about
3+
// handling ClearState, because the ClearStateProgram will execute in that
4+
// case, not the ApprovalProgram.
5+
6+
txn ApplicationID
7+
int 0
8+
==
9+
bnz handle_approve
10+
11+
txn OnCompletion
12+
int NoOp
13+
==
14+
bnz handle_noop
15+
16+
txn OnCompletion
17+
int OptIn
18+
==
19+
bnz handle_approve
20+
21+
txn OnCompletion
22+
int CloseOut
23+
==
24+
bnz handle_closeout
25+
26+
txn OnCompletion
27+
int UpdateApplication
28+
==
29+
bnz handle_updateapp
30+
31+
txn OnCompletion
32+
int DeleteApplication
33+
==
34+
bnz handle_deleteapp
35+
36+
// Unexpected OnCompletion value. Should be unreachable.
37+
err
38+
39+
handle_noop:
40+
// Handle NoOp
41+
42+
// read global state
43+
byte "counter"
44+
dup
45+
app_global_get
46+
47+
// increment the value
48+
int 1
49+
+
50+
51+
// store to scratch space
52+
dup
53+
store 0
54+
55+
// update global state
56+
app_global_put
57+
58+
// read local state for sender
59+
int 0
60+
byte "counter"
61+
app_local_get
62+
63+
// increment the value
64+
int 1
65+
+
66+
store 1
67+
68+
// update local state for sender
69+
// update "counter"
70+
int 0
71+
byte "counter"
72+
load 1
73+
app_local_put
74+
75+
// update "timestamp"
76+
int 0
77+
byte "timestamp"
78+
txn ApplicationArgs 0
79+
app_local_put
80+
81+
// load return value as approval
82+
load 0
83+
return
84+
85+
handle_closeout:
86+
// Handle CloseOut
87+
//approval
88+
int 1
89+
return
90+
91+
handle_deleteapp:
92+
// Check for creator
93+
global CreatorAddress
94+
txn Sender
95+
==
96+
return
97+
98+
handle_updateapp:
99+
// Check for creator
100+
global CreatorAddress
101+
txn Sender
102+
==
103+
return
104+
105+
handle_approve:
106+
int 1
107+
return

_examples/application/clear.teal

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma version 4
2+
int 1
3+
return

0 commit comments

Comments
 (0)