def buyer_place_order(self, product, proxy): buyer_rsa_pubkey = self.rsa_public_key desc_hash = Encoder.str_to_base64_byte(product['msg_hash']) public_key = ECCipher.create_public_key( Encoder.hex_to_bytes(product['owner_address'])) seller_addr = w3.toChecksumAddress( ECCipher.get_address_from_public_key(public_key)) proxy = w3.toChecksumAddress(proxy) product = OrderInfo(desc_hash=desc_hash, buyer_rsa_pubkey=buyer_rsa_pubkey, seller=seller_addr, proxy=proxy, secondary_proxy=proxy, proxy_value=100, value=product['price'], time_allowed=3600 * 24) w3.personal.unlockAccount(self.account.address, _passphrase) order_id = self.buyer_agent.place_order(product) # w3.personal.lockAccount(self.account.address) # return -1 if failure return order_id
def __init__(self, wallet): self.wallet = wallet bin_path = join_with_root(config.chain.contract_bin_path) # deploy_contract(bin_path, config.chain.contract_name, default_w3) account = get_address_from_public_key_object(self.wallet.market_client.public_key) if default_w3: account = default_w3.toChecksumAddress(account) self.buyer = BuyerAgent(default_w3, bin_path, config.chain.contract_name, account) self.seller = SellerAgent(default_w3, bin_path, config.chain.contract_name, account) self.handler = Handler(self) self.monitor = Monitor(self)
def __login(account=None): if account is None: wallet.accounts.set_default_account(1) account = wallet.accounts.default_account public_key = ECCipher.serialize_public_key(account.public_key) addr = utils.get_address_from_public_key_object(public_key) addr = web3.toChecksumAddress(addr) app.addr = addr if isinstance(account.key_passphrase, str): app.pwd = account.key_passphrase else: app.pwd = account.key_passphrase.decode() wallet.market_client.account = account wallet.market_client.public_key = ECCipher.serialize_public_key( wallet.market_client.account.public_key) wallet.market_client.login(app.username).addCallbacks( lambda _: event.emit(events.LOGIN_COMPLETED)) wallet.init() initialize_system() app.router.redirectTo('market_page')
def login(): path = os.path.expanduser('~/.cpchain') if not os.path.exists(path): os.mkdir(path) with shelve.open(os.path.join(path, 'account')) as file: key_path = file.get('key_path') key_passphrase = file.get('key_passphrase') try: app.timing(logger, 'Data Init') if key_path and key_passphrase: if isinstance(key_passphrase, str): account = Account(key_path, key_passphrase.encode()) else: account = Account(key_path, key_passphrase) public_key = ECCipher.serialize_public_key(account.public_key) # Init market client account wallet.market_client.account = account wallet.market_client.public_key = public_key app.timing(logger, 'Account Prepare') addr = utils.get_address_from_public_key_object(public_key) addr = web3.toChecksumAddress(addr) logger.info(addr) app.addr = addr if isinstance(key_passphrase, str): app.pwd = key_passphrase else: app.pwd = key_passphrase.decode() wallet.market_client.query_username(app) __unlock() app.timing(logger, 'Unlock') enterPDash(account) return except Exception as e: logger.error(e) logger.debug('Init') wnd = LoginWindow(reactor) wnd.show() wallet.set_main_wnd(wnd)
def lock_account(account): addr = crypto.ECCipher.get_address_from_public_key(account.public_key) web3.personal.lockAccount(web3.toChecksumAddress(addr))
def unlock_account(account): addr = crypto.ECCipher.get_address_from_public_key(account.public_key) web3.personal.unlockAccount(web3.toChecksumAddress(addr), account.key_passphrase)
contract = deploy_contract(bin_path, contract_name) registrar_path = join_with_root(config.chain.registrar_json) with open(registrar_path, 'w') as f: f.write(json.dumps(dict({contract_name: contract.address}))) print("contract address: %s" % contract.address) if __name__ == "__main__": import sys from getpass import getpass from cpchain.chain.utils import default_w3 as web3 if len(sys.argv) != 2: print("Need pre-funded account as sender, i.e. 22114f40ed222e83bbd88dc6cbb3b9a136299a23") sys.exit(1) account = web3.toChecksumAddress(sys.argv[1]) passwd = getpass('please input keyphrase for your account: ') web3.personal.unlockAccount(account, passwd) # deploy_contract() uses web3.eth.defaultAccount as sender web3.eth.defaultAccount = account main() web3.personal.lockAccount(account)