Skip to content

Commit

Permalink
more clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
voith committed Jan 28, 2019
1 parent 0d08854 commit 400f4fe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 29 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ install:
# command to run tests, e.g. python setup.py test
script: tox -e ${TOXENV}


6 changes: 1 addition & 5 deletions sto/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,7 @@ def kyc_manage(config: BoardCommmadConfiguration, whitelist_address):
"""
from sto.ethereum.utils import whitelist_kyc_address
whitelist_kyc_address(
dbsession=config.dbsession,
ethereum_private_key=config.ethereum_private_key,
ethereum_abi_file=config.ethereum_abi_file,
ethereum_node_url=config.ethereum_node_url,
ethereum_gas_limit=config.ethereum_gas_limit,
config=config,
address=whitelist_address
)

Expand Down
50 changes: 26 additions & 24 deletions sto/ethereum/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,36 +287,38 @@ def get_contract_deployed_tx(dbsession, contract_name):
).first()


def whitelist_kyc_address(
dbsession,
ethereum_private_key,
ethereum_abi_file,
ethereum_node_url,
ethereum_gas_limit,
address
):
from web3.middleware.signing import construct_sign_and_send_raw_middleware
from eth_account import Account
tx = get_contract_deployed_tx(dbsession, 'BasicKYC')
def whitelist_kyc_address(config, address):
from sto.ethereum.txservice import EthereumStoredTXService
from sto.models.implementation import BroadcastAccount, PreparedTransaction

tx = get_contract_deployed_tx(config.dbsession, 'BasicKYC')
if not tx:
raise Exception(
'BasicKyc contract is not deployed. '
'invoke command kyc_deploy to deploy the smart contract'
)

check_good_private_key(ethereum_private_key)

abi = get_abi(ethereum_abi_file)
abi = abi['BasicKYC']['abi']
web3 = create_web3(config.ethereum_node_url)

w3 = create_web3(ethereum_node_url)
service = EthereumStoredTXService(
config.network,
config.dbsession,
web3,
config.ethereum_private_key,
config.ethereum_gas_price,
config.ethereum_gas_limit,
BroadcastAccount,
PreparedTransaction
)
abi = get_abi(config.ethereum_abi_file)

contract = w3.eth.contract(address=tx.contract_address, abi=abi)
w3.middleware_stack.add(construct_sign_and_send_raw_middleware(ethereum_private_key))
account = Account.privateKeyToAccount(ethereum_private_key)
tx_hash = contract.functions.whitelistUser(address, True).transact(
{'from': account.address, 'gas': ethereum_gas_limit}
service.interact_with_contract(
contract_name='BasicKYC',
abi=abi,
address=tx.contract_address,
note='whitelisting address {0}'.format(address),
func_name='whitelistUser',
args={'who': address, 'status': True}
)
receipt = w3.eth.waitForTransactionReceipt(tx_hash)
assert receipt['status'] == 1, "failed to whitelist address"
assert contract.functions.isWhitelisted(address).call() == True, "isWhitelisted failed"
broadcast(config)

0 comments on commit 400f4fe

Please sign in to comment.