def message2signature(raw, address): # sign by address with closing(create_db(V.DB_ACCOUNT_PATH)) as db: cur = db.cursor() uuid, sk, pk = read_address2keypair(address, cur) if sk is None: raise BlockChainError('Not found address {}'.format(address)) return pk, sign(msg=raw, sk=sk, pk=pk)
async def validateaddress(*args, **kwargs): """ Arguments: 1. "address" (string, required) The bitcoin address to validate Result: { "isvalid" : true|false, (boolean) If the address is valid or not. If not, this is the only property returned. "address" : "address", (string) The bitcoin address validated "ismine" : true|false, (boolean) If the address is yours or not "pubkey" : "publickeyhex", (string, optional) The hex value of the raw public key, for single-key addresses (possibly embedded in P2SH or P2WSH) "account" : "account" (string) DEPRECATED. The account associated with the address, "" is the default account "hdkeypath" : "keypath" (string, optional) The HD keypath if the key is HD and available } """ if len(args) == 0: raise ValueError('no argument found') address = args[0] with create_db(V.DB_ACCOUNT_PATH) as db: cur = db.cursor() user_id = read_address2userid(address=address, cur=cur) if user_id is None: return { "isvalid": is_address(address, V.BECH32_HRP, 0), "address": address, "ismine": False, "pubkey": None, "account": None, "hdkeypath": None, } else: account = read_userid2name(user=user_id, cur=cur) account = "" if account == C.ANT_UNKNOWN else account _, keypair, path = read_address2keypair(address=address, cur=cur) return { "isvalid": is_address(address, V.BECH32_HRP, 0), "address": address, "ismine": True, "pubkey": keypair.get_public_key().hex(), "account": account, "hdkeypath": path, }
def change_mintcoin(mint_id, cur, amount=0, message=None, additional_issue=None, image=None, sender=C.ANT_UNKNOWN): mint_old = get_mintcoin(mint_id) assert mint_old, 'Not defined MintCoin {}'.format(mint_id) mint_new = MintCoinObject(None) mint_new.version = mint_old.version + 1 mint_new.coin_id = mint_id mint_new.amount = amount mint_new.additional_issue = additional_issue mint_address = get_address(mint_old.owner, prefix=V.BLOCK_PREFIX) uuid, sk, pk = read_address2keypair(mint_address, cur) mint_new.owner = pk mint_new.image = image mint_new.message = message # マージチェック mint_new.marge(mint_old) # Message内署名 mint_new.generate_sign(sk) mint_new.serialize() mint_new.check_param() mint_new.check_sign() logging.info("New Mintcoin skeleton created coin_id={}".format( mint_new.coin_id)) # movement movements = UserCoins() minting_coins = CoinObject(mint_id, amount) movements[sender] += minting_coins movements[C.ANT_OUTSIDE] -= minting_coins # TXを作成する base_coin_id = 0 now = int(time.time()) - V.BLOCK_GENESIS_TIME tx = TX( tx={ 'version': __chain_version__, 'type': C.TX_MINT_COIN, 'time': now, 'deadline': now + 10800, 'inputs': list(), 'outputs': [(MINTCOIN_DUMMY_ADDRESS, base_coin_id, amount)] if 0 < amount else list(), 'gas_price': V.COIN_MINIMUM_PRICE, 'gas_amount': 1, 'message_type': C.MSG_BYTE, 'message': mint_new.binary }) tx.gas_amount = tx.getsize() + 96 + C.MINTCOIN_FEE tx.serialize() fee_coin_id = 0 input_address = fill_inputs_outputs(tx, cur, fee_coin_id, C.MINTCOIN_FEE) fee_coins = CoinObject(fee_coin_id, tx.gas_price * tx.gas_amount) # check amount check_enough_amount(sender, CoinObject(base_coin_id, amount), fee_coins) # replace dummy address replace_redeem_dummy_address(tx, cur) # replace dummy mint_id if amount > 0: replace_mint_dummy_address(tx, mint_address, mint_id) # setup signature tx.serialize() setup_signature(tx, input_address) movements[sender] -= fee_coins movements[C.ANT_OUTSIDE] += fee_coins insert_log(movements, cur, tx.type, tx.time, tx.hash) return mint_new, tx
def issue_mintcoin(name, unit, amount, digit, cur, gas_price=None, message='', additional_issue=True, image=None, sender=C.ANT_UNKNOWN): mint = MintCoinObject(None) new_mint_id = get_new_coin_id() mint.version = 0 mint.coin_id = new_mint_id mint.name = name mint.unit = unit mint.digit = digit mint.supply_before = 0 mint.amount = amount mint.additional_issue = additional_issue new_mint_address = create_new_user_keypair(C.ANT_NAME_UNKNOWN, cur) uuid, sk, pk = read_address2keypair(new_mint_address, cur) mint.owner = pk mint.image = image mint.message = message # Message内署名 mint.generate_sign(sk) mint.serialize() mint.check_param() mint.check_sign() logging.info("New Mintcoin skeleton created coin_id={}".format( mint.coin_id)) # movement movements = UserCoins() minting_coins = CoinObject(new_mint_id, amount) movements[sender] += minting_coins movements[C.ANT_OUTSIDE] -= minting_coins # TXを作成する base_coin_id = 0 now = int(time.time()) - V.BLOCK_GENESIS_TIME tx = TX( tx={ 'version': __chain_version__, 'type': C.TX_MINT_COIN, 'time': now, 'deadline': now + 10800, 'inputs': list(), 'outputs': [(MINTCOIN_DUMMY_ADDRESS, base_coin_id, amount)], 'gas_price': gas_price or V.COIN_MINIMUM_PRICE, 'gas_amount': 1, 'message_type': C.MSG_BYTE, 'message': mint.binary }) tx.gas_amount = tx.getsize() + 96 + C.MINTCOIN_FEE tx.serialize() # fill unspents fee_coin_id = 0 input_address = fill_inputs_outputs(tx, cur, fee_coin_id, C.MINTCOIN_FEE) fee_coins = CoinObject(fee_coin_id, tx.gas_price * tx.gas_amount) # check amount check_enough_amount(sender, CoinObject(base_coin_id, amount), fee_coins) # replace dummy address replace_redeem_dummy_address(tx, cur) # replace dummy mint_id replace_mint_dummy_address(tx, new_mint_address, new_mint_id) # setup signature tx.serialize() setup_signature(tx, input_address) movements[sender] -= fee_coins movements[C.ANT_OUTSIDE] += fee_coins insert_log(movements, cur, tx.type, tx.time, tx.hash) return mint, tx
def message2signature(raw, address): # sign by address with closing(create_db(V.DB_ACCOUNT_PATH)) as db: cur = db.cursor() uuid, sk, pk = read_address2keypair(address, cur) return pk, sign(msg=raw, sk=sk, pk=pk)