Skip to content

Commit

Permalink
add bac and mixer abi and bin
Browse files Browse the repository at this point in the history
  • Loading branch information
yanyanho committed Aug 7, 2020
1 parent c603414 commit a50772d
Show file tree
Hide file tree
Showing 18 changed files with 323 additions and 261 deletions.
11 changes: 7 additions & 4 deletions commands/zeth_deploy.py

Large diffs are not rendered by default.

33 changes: 17 additions & 16 deletions commands/zeth_token_approve.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,47 @@

from commands.utils import EtherValue
from click import ClickException

from contract.BAC001 import BAC001
from contract.Groth16Mixer import Groth16Mixer
from contract.ERC20Mintable import ERC20Mintable
from python_web3.eth_account.account import Account
from python_web3.client.bcoskeypair import BcosKeyPair
from commands.constants import USER_DIR, FISCO_ADDRESS_FILE
import json
from os.path import exists


def token_approve(tokens: str, mixer_addr: str, token_addr: str, username: str, password: str) :
def asset_approve(assets: str, mixer_addr: str, asset_addr: str, username: str, password: str) :
"""
Approve the mixer to spend some amount of tokens
Approve the mixer to spend some amount of assets
"""
approve_value = EtherValue(tokens)
approve_value = EtherValue(assets)
#eth_addr = load_eth_address(eth_addr)
#client_ctx = ctx.obj
#web3 = open_web3_from_ctx(client_ctx)
#mixer_desc = load_mixer_description_from_ctx(client_ctx)
#if not mixer_desc.token:
# raise ClickException("no token for mixer {mixer_desc.mixer.address}")
#if not mixer_desc.asset:
# raise ClickException("no asset for mixer {mixer_desc.mixer.address}")

token_instance = ERC20Mintable(token_addr)
asset_instance = BAC001(asset_addr)
keystore_file = "{}/{}/{}".format(USER_DIR, username, FISCO_ADDRESS_FILE)
with open(keystore_file, "r") as dump_f:
keytext = json.load(dump_f)
privkey = Account.decrypt(keytext, password)
token_instance.client.ecdsa_account = Account.from_key(privkey)
asset_instance.client.ecdsa_account = Account.from_key(privkey)
keypair = BcosKeyPair()
keypair.private_key = token_instance.client.ecdsa_account.privateKey
keypair.public_key = token_instance.client.ecdsa_account.publickey
keypair.address = token_instance.client.ecdsa_account.address
token_instance.client.keypair = keypair
print(f"- {username} approves the transfer of ERC20Token to the Mixer")
out, transactionReceipt = token_instance.approve(
keypair.private_key = asset_instance.client.ecdsa_account.privateKey
keypair.public_key = asset_instance.client.ecdsa_account.publickey
keypair.address = asset_instance.client.ecdsa_account.address
asset_instance.client.keypair = keypair
print(f"- {username} approves the transfer of BAC001asset to the Mixer")
out, transactionReceipt = asset_instance.approve(
mixer_addr,
approve_value.wei)
print("approve tranaction output", out)
outputresult = token_instance.allowance(token_instance.client.ecdsa_account.address, mixer_addr)
outputresult = asset_instance.allowance(asset_instance.client.ecdsa_account.address, mixer_addr)
print(f"- The allowance for the Mixer from {username} is: {outputresult}")
return outputresult

if __name__ == '__main__':
token_approve()
asset_approve()
50 changes: 31 additions & 19 deletions commands/zeth_token_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,45 @@
from zeth.mixer_client import MixerClient
from zeth.utils import EtherValue
'''
import json

from click import Context, command, option, pass_context
from typing import Optional
from web3 import Web3
from contract.ERC20Mintable import ERC20Mintable
#from test_commands.deploy_test_token import mint_token

#from test_commands.deploy_test_asset import mint_asset
from contract.BAC001 import BAC001
from python_web3.client.bcosclient import BcosClient


def deploy_token(
miner_address: Optional[str],
token_amount: Optional[int]
def deploy_asset(
description,
shortName,
minUnit,
total_amount: Optional[int]
) :
"""
Deploy the zeth contracts and record the instantiation details.
"""
token_si = ERC20Mintable("")
token_result = token_si.deploy("contract/ERC20Mintable.bin")
token_address = token_result['contractAddress']
token_instance = ERC20Mintable(token_address)
print(f"deploy: token_address={token_address}")
token_instance.mint(
miner_address,
Web3.toWei(token_amount, 'ether'))
print("- Initial balances: ")
outputresult = token_instance.balanceOf(miner_address)
print(f" {miner_address} : {outputresult}")
return token_address
# description, string memory shortName, uint8 minUnit, uint256 totalAmount
constructArgs= [description,shortName,18,total_amount]
fo = open("./contract/bac/abi/BAC001.abi")
abi = fo.read()
fo.close()
f1 = open("./contract/bac/abi/BAC001.bin")
bin = f1.read()
f1.close()
client = BcosClient()
assetTransactionRecipient = client.sendRawTransactionGetReceipt("", abi, None, constructArgs, bin, 30000000, 15)
asset_address = assetTransactionRecipient['contractAddress']
asset_instance = BAC001(asset_address)
print(f"deploy: asset_address= {asset_address}")
# asset_instance.issue(
# miner_address,
# Web3.toWei(asset_amount, 'ether'), '')
# print("- Initial balances: ")
# outputresult = asset_instance.balanceOf(miner_address)
# print(f" {miner_address} : {outputresult}")
return asset_address

if __name__ == '__main__':
deploy_token()
deploy_asset()
1 change: 1 addition & 0 deletions contract/BAC001.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{'inputs': [{'internalType': 'string', 'name': 'description', 'type': 'string'}, {'internalType': 'string', 'name': 'shortName', 'type': 'string'}, {'internalType': 'uint8', 'name': 'minUnit', 'type': 'uint8'}, {'internalType': 'uint256', 'name': 'totalAmount', 'type': 'uint256'}], 'payable': False, 'stateMutability': 'nonpayable', 'type': 'constructor'}, {'anonymous': False, 'inputs': [{'indexed': True, 'internalType': 'address', 'name': 'owner', 'type': 'address'}, {'indexed': True, 'internalType': 'address', 'name': 'spender', 'type': 'address'}, {'indexed': False, 'internalType': 'uint256', 'name': 'value', 'type': 'uint256'}], 'name': 'Approval', 'type': 'event'}, {'anonymous': False, 'inputs': [{'indexed': True, 'internalType': 'address', 'name': 'account', 'type': 'address'}], 'name': 'IssuerAdded', 'type': 'event'}, {'anonymous': False, 'inputs': [{'indexed': True, 'internalType': 'address', 'name': 'account', 'type': 'address'}], 'name': 'IssuerRemoved', 'type': 'event'}, {'anonymous': False, 'inputs': [{'indexed': True, 'internalType': 'address', 'name': 'from', 'type': 'address'}, {'indexed': True, 'internalType': 'address', 'name': 'to', 'type': 'address'}, {'indexed': False, 'internalType': 'uint256', 'name': 'value', 'type': 'uint256'}, {'indexed': False, 'internalType': 'bytes', 'name': 'data', 'type': 'bytes'}], 'name': 'Send', 'type': 'event'}, {'anonymous': False, 'inputs': [{'indexed': False, 'internalType': 'address', 'name': 'account', 'type': 'address'}], 'name': 'Suspended', 'type': 'event'}, {'anonymous': False, 'inputs': [{'indexed': True, 'internalType': 'address', 'name': 'account', 'type': 'address'}], 'name': 'SuspenderAdded', 'type': 'event'}, {'anonymous': False, 'inputs': [{'indexed': True, 'internalType': 'address', 'name': 'account', 'type': 'address'}], 'name': 'SuspenderRemoved', 'type': 'event'}, {'anonymous': False, 'inputs': [{'indexed': False, 'internalType': 'address', 'name': 'account', 'type': 'address'}], 'name': 'UnSuspended', 'type': 'event'}, {'constant': False, 'inputs': [{'internalType': 'address', 'name': 'account', 'type': 'address'}], 'name': 'addIssuer', 'outputs': [], 'payable': False, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': False, 'inputs': [{'internalType': 'address', 'name': 'account', 'type': 'address'}], 'name': 'addSuspender', 'outputs': [], 'payable': False, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': True, 'inputs': [{'internalType': 'address', 'name': 'owner', 'type': 'address'}, {'internalType': 'address', 'name': 'spender', 'type': 'address'}], 'name': 'allowance', 'outputs': [{'internalType': 'uint256', 'name': '', 'type': 'uint256'}], 'payable': False, 'stateMutability': 'view', 'type': 'function'}, {'constant': False, 'inputs': [{'internalType': 'address', 'name': 'spender', 'type': 'address'}, {'internalType': 'uint256', 'name': 'value', 'type': 'uint256'}], 'name': 'approve', 'outputs': [{'internalType': 'bool', 'name': '', 'type': 'bool'}], 'payable': False, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': True, 'inputs': [{'internalType': 'address', 'name': 'owner', 'type': 'address'}], 'name': 'balance', 'outputs': [{'internalType': 'uint256', 'name': '', 'type': 'uint256'}], 'payable': False, 'stateMutability': 'view', 'type': 'function'}, {'constant': False, 'inputs': [{'internalType': 'address[]', 'name': 'to', 'type': 'address[]'}, {'internalType': 'uint256[]', 'name': 'values', 'type': 'uint256[]'}, {'internalType': 'bytes', 'name': 'data', 'type': 'bytes'}], 'name': 'batchSend', 'outputs': [], 'payable': False, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': False, 'inputs': [{'internalType': 'address', 'name': 'spender', 'type': 'address'}, {'internalType': 'uint256', 'name': 'subtractedValue', 'type': 'uint256'}], 'name': 'decreaseAllowance', 'outputs': [{'internalType': 'bool', 'name': '', 'type': 'bool'}], 'payable': False, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': True, 'inputs': [], 'name': 'description', 'outputs': [{'internalType': 'string', 'name': '', 'type': 'string'}], 'payable': False, 'stateMutability': 'view', 'type': 'function'}, {'constant': False, 'inputs': [{'internalType': 'uint256', 'name': 'value', 'type': 'uint256'}, {'internalType': 'bytes', 'name': 'data', 'type': 'bytes'}], 'name': 'destroy', 'outputs': [], 'payable': False, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': False, 'inputs': [{'internalType': 'address', 'name': 'from', 'type': 'address'}, {'internalType': 'uint256', 'name': 'value', 'type': 'uint256'}, {'internalType': 'bytes', 'name': 'data', 'type': 'bytes'}], 'name': 'destroyFrom', 'outputs': [], 'payable': False, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': False, 'inputs': [{'internalType': 'address', 'name': 'spender', 'type': 'address'}, {'internalType': 'uint256', 'name': 'addedValue', 'type': 'uint256'}], 'name': 'increaseAllowance', 'outputs': [{'internalType': 'bool', 'name': '', 'type': 'bool'}], 'payable': False, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': True, 'inputs': [{'internalType': 'address', 'name': 'account', 'type': 'address'}], 'name': 'isIssuer', 'outputs': [{'internalType': 'bool', 'name': '', 'type': 'bool'}], 'payable': False, 'stateMutability': 'view', 'type': 'function'}, {'constant': True, 'inputs': [{'internalType': 'address', 'name': 'account', 'type': 'address'}], 'name': 'isSuspender', 'outputs': [{'internalType': 'bool', 'name': '', 'type': 'bool'}], 'payable': False, 'stateMutability': 'view', 'type': 'function'}, {'constant': False, 'inputs': [{'internalType': 'address', 'name': 'to', 'type': 'address'}, {'internalType': 'uint256', 'name': 'value', 'type': 'uint256'}, {'internalType': 'bytes', 'name': 'data', 'type': 'bytes'}], 'name': 'issue', 'outputs': [{'internalType': 'bool', 'name': '', 'type': 'bool'}], 'payable': False, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': True, 'inputs': [], 'name': 'minUnit', 'outputs': [{'internalType': 'uint8', 'name': '', 'type': 'uint8'}], 'payable': False, 'stateMutability': 'view', 'type': 'function'}, {'constant': False, 'inputs': [], 'name': 'renounceIssuer', 'outputs': [], 'payable': False, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': False, 'inputs': [], 'name': 'renounceSuspender', 'outputs': [], 'payable': False, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': False, 'inputs': [{'internalType': 'address', 'name': 'to', 'type': 'address'}, {'internalType': 'uint256', 'name': 'value', 'type': 'uint256'}, {'internalType': 'bytes', 'name': 'data', 'type': 'bytes'}], 'name': 'send', 'outputs': [], 'payable': False, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': False, 'inputs': [{'internalType': 'address', 'name': 'from', 'type': 'address'}, {'internalType': 'address', 'name': 'to', 'type': 'address'}, {'internalType': 'uint256', 'name': 'value', 'type': 'uint256'}, {'internalType': 'bytes', 'name': 'data', 'type': 'bytes'}], 'name': 'sendFrom', 'outputs': [], 'payable': False, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': True, 'inputs': [], 'name': 'shortName', 'outputs': [{'internalType': 'string', 'name': '', 'type': 'string'}], 'payable': False, 'stateMutability': 'view', 'type': 'function'}, {'constant': False, 'inputs': [], 'name': 'suspend', 'outputs': [], 'payable': False, 'stateMutability': 'nonpayable', 'type': 'function'}, {'constant': True, 'inputs': [], 'name': 'suspended', 'outputs': [{'internalType': 'bool', 'name': '', 'type': 'bool'}], 'payable': False, 'stateMutability': 'view', 'type': 'function'}, {'constant': True, 'inputs': [], 'name': 'totalAmount', 'outputs': [{'internalType': 'uint256', 'name': '', 'type': 'uint256'}], 'payable': False, 'stateMutability': 'view', 'type': 'function'}, {'constant': False, 'inputs': [], 'name': 'unSuspend', 'outputs': [], 'payable': False, 'stateMutability': 'nonpayable', 'type': 'function'}]
1 change: 1 addition & 0 deletions contract/BAC001.bin

Large diffs are not rendered by default.

Loading

0 comments on commit a50772d

Please sign in to comment.