This repository has been archived by the owner on Jul 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #610 from kjeom/refactorAccountManagement
refactor account management examples
- Loading branch information
Showing
17 changed files
with
182 additions
and
118 deletions.
There are no files selected for viewing
20 changes: 0 additions & 20 deletions
20
web3py-ext/web3py_ext/example/account/1-pubkey_rlp_encode_decode.py
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
web3py-ext/web3py_ext/example/account/2-multisig_rlp_encode_decode.py
This file was deleted.
Oops, something went wrong.
48 changes: 0 additions & 48 deletions
48
web3py-ext/web3py_ext/example/account/3-role_based_rlp_encode_decode.py
This file was deleted.
Oops, something went wrong.
File renamed without changes.
43 changes: 43 additions & 0 deletions
43
web3py-ext/web3py_ext/example/account/account_update/1-legacy_account_key.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#-*- coding:utf-8 -*- | ||
from web3py_ext import extend | ||
from web3 import Web3 | ||
from eth_account import Account | ||
from web3py_ext.klaytn_account.utils import compressed_key | ||
from web3py_ext.klaytn_account.account_key import KeyType | ||
from web3py_ext.transaction.transaction import ( | ||
empty_tx, | ||
fill_transaction, | ||
TxType | ||
) | ||
from web3py_ext.utils.klaytn_utils import ( | ||
to_pretty, | ||
bytes_to_hex_str | ||
) | ||
from cytoolz import merge | ||
|
||
w3 = Web3(Web3.HTTPProvider('https://public-en-baobab.klaytn.net')) | ||
|
||
def web3_account_update_legacy(): | ||
user = Account.from_key('0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8') | ||
|
||
account_update_tx = empty_tx(TxType.ACCOUNT_UPDATE) | ||
account_update_tx = merge(account_update_tx, { | ||
'from' : user.address, | ||
'key' : { | ||
'type': KeyType.LEGACY, | ||
'key': {}, | ||
} | ||
}) | ||
account_update_tx = fill_transaction(account_update_tx, w3) | ||
print(to_pretty(account_update_tx)) | ||
|
||
# sign the klaytn specific transaction type with web3py | ||
signed_tx = Account.sign_transaction(account_update_tx, user.key) | ||
print('\nrawTransaction:', bytes_to_hex_str(signed_tx.rawTransaction)) | ||
|
||
# temddp test | ||
tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction) | ||
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash) | ||
print('tx hash: ', tx_hash, 'receipt: ', tx_receipt) | ||
|
||
web3_account_update_legacy() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
web3py-ext/web3py_ext/example/account/account_update/3-multisig_account_key.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#-*- coding:utf-8 -*- | ||
from web3py_ext import extend | ||
from web3 import Web3 | ||
from eth_account import Account | ||
from web3py_ext.klaytn_account.utils import compressed_key | ||
from web3py_ext.klaytn_account.account_key import KeyType | ||
from web3py_ext.transaction.transaction import ( | ||
empty_tx, | ||
fill_transaction, | ||
TxType | ||
) | ||
from web3py_ext.utils.klaytn_utils import ( | ||
to_pretty, | ||
bytes_to_hex_str | ||
) | ||
from cytoolz import merge | ||
|
||
w3 = Web3(Web3.HTTPProvider('https://public-en-baobab.klaytn.net')) | ||
|
||
def web3_account_update_multisig(): | ||
user1 = Account.from_key("0xa32c30608667d43be2d652bede413f12a649dd1be93440878e7f712d51a6768a") | ||
user2 = Account.from_key("0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8") | ||
user3 = Account.from_key("0xc9668ccd35fc20587aa37a48838b48ccc13cf14dd74c8999dd6a480212d5f7ac") | ||
|
||
account_update_tx = empty_tx(TxType.ACCOUNT_UPDATE) | ||
account_update_tx = merge(account_update_tx, { | ||
'from' : user1.address, #0x82c6a8d94993d49cfd0c1d30f0f8caa65782cc7e | ||
'key' : { | ||
'type': KeyType.MULTISIG, | ||
'threshold': 2, | ||
'keys': [ | ||
{ | ||
'weight':1, | ||
'key': compressed_key(user1), | ||
}, | ||
{ | ||
'weight':1, | ||
'key': compressed_key(user2), | ||
}, | ||
{ | ||
'weight':1, | ||
'key': compressed_key(user3), | ||
}, | ||
] | ||
} | ||
}) | ||
account_update_tx = fill_transaction(account_update_tx, w3) | ||
print(to_pretty(account_update_tx)) | ||
|
||
# sign the klaytn specific transaction type with web3py | ||
signed_tx = Account.sign_transaction(account_update_tx, user1.key) | ||
signed_tx = Account.sign_transaction(signed_tx.rawTransaction, user2.key) | ||
signed_tx = Account.sign_transaction(signed_tx.rawTransaction, user3.key) | ||
print('\nrawTransaction:', bytes_to_hex_str(signed_tx.rawTransaction)) | ||
|
||
tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction) | ||
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash) | ||
print('tx hash: ', tx_hash, 'receipt: ', tx_receipt) | ||
|
||
web3_account_update_multisig() |
58 changes: 58 additions & 0 deletions
58
web3py-ext/web3py_ext/example/account/account_update/4-role_based_account_key.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#-*- coding:utf-8 -*- | ||
from web3py_ext import extend | ||
from web3 import Web3 | ||
from eth_account import Account | ||
from web3py_ext.klaytn_account.utils import compressed_key | ||
from web3py_ext.klaytn_account.account_key import KeyType | ||
from web3py_ext.transaction.transaction import ( | ||
empty_tx, | ||
fill_transaction, | ||
TxType | ||
) | ||
from web3py_ext.utils.klaytn_utils import ( | ||
to_pretty, | ||
bytes_to_hex_str | ||
) | ||
from cytoolz import merge | ||
|
||
w3 = Web3(Web3.HTTPProvider('https://public-en-baobab.klaytn.net')) | ||
|
||
def web3_account_update_role_based(): | ||
# Just for testing, user1 and user2 have the same key | ||
tx_role = Account.from_key("0xc9668ccd35fc20587aa37a48838b48ccc13cf14dd74c8999dd6a480212d5f7ac"); | ||
update_role = Account.from_key("0x9ba8cb8f60044058a9e6f815c5c42d3a216f47044c61a1750b6d29ddc7f34bda"); | ||
fee_payer_role = Account.from_key("0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8"); | ||
|
||
account_update_tx = empty_tx(TxType.ACCOUNT_UPDATE) | ||
account_update_tx = merge(account_update_tx, { | ||
'from' : update_role.address, # 0x5bd2fb3c21564c023a4a735935a2b7a238c4ccea | ||
'key' : { | ||
'type': KeyType.ROLE_BASED, | ||
'keys' : { | ||
'roleTransactionKey': { | ||
'type': KeyType.PUBLIC, | ||
'key': compressed_key(tx_role) | ||
}, | ||
'roleAccountUpdateKey': { | ||
'type': KeyType.PUBLIC, | ||
'key': compressed_key(update_role) | ||
}, | ||
'roleFeePayerKey': { | ||
'type': KeyType.PUBLIC, | ||
'key': compressed_key(fee_payer_role) | ||
} | ||
} | ||
} | ||
}) | ||
account_update_tx = fill_transaction(account_update_tx, w3) | ||
print(to_pretty(account_update_tx)) | ||
|
||
# sign the klaytn specific transaction type with web3py | ||
signed_tx = Account.sign_transaction(account_update_tx, update_role.key) | ||
print('\nrawTransaction:', bytes_to_hex_str(signed_tx.rawTransaction)) | ||
|
||
tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction) | ||
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash) | ||
print('tx hash: ', tx_hash, 'receipt: ', tx_receipt) | ||
|
||
web3_account_update_role_based() |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.