Skip to content

Commit

Permalink
update to v0.2.1 (#2)
Browse files Browse the repository at this point in the history
update from cryptogarageinc v0.2.1 (#2)
  • Loading branch information
k-matsuzawa authored Oct 30, 2020
1 parent f1de800 commit b8ec6e6
Show file tree
Hide file tree
Showing 6 changed files with 242 additions and 4 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.0
0.2.1
19 changes: 18 additions & 1 deletion cfd/confidential_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# @file confidential_address.py
# @brief elements confidential address function implements file.
# @note Copyright 2020 CryptoGarage
from .util import get_util, to_hex_string
from .util import get_util, to_hex_string, CfdError


##
Expand All @@ -20,6 +20,23 @@ class ConfidentialAddress:
# @var confidential_key
# confidential key

##
# @brief check confidential address.
# @param[in] confidential_address confidential address
# @retval True confidential address
# @retval False other
@classmethod
def valid(cls, confidential_address):
util = get_util()
try:
with util.create_handle() as handle:
_, _, _ = util.call_func(
'CfdParseConfidentialAddress', handle.get_handle(),
str(confidential_address))
return True
except CfdError:
return False

##
# @brief parse confidential address.
# @param[in] confidential_address confidential address
Expand Down
22 changes: 21 additions & 1 deletion cfd/confidential_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
# @note Copyright 2020 CryptoGarage
from .util import ReverseByteData, CfdError, JobHandle,\
CfdErrorCode, to_hex_string, get_util, ByteData
from .address import Address, AddressUtil
from .key import Network, SigHashType, Privkey
from .script import HashType
from .transaction import UtxoData, OutPoint, Txid, TxIn, TxOut, _FundTxOpt,\
_TransactionBase
from .confidential_address import ConfidentialAddress
from enum import Enum
import copy
import ctypes
Expand Down Expand Up @@ -1379,10 +1381,28 @@ def set_opt(handle, tx_handle, key, i_val=0, f_val=0, b_val=False):
tx_handle.get_handle(), key.value,
int(i_val), float(f_val), b_val)

network = self.NETWORK
for target in target_list:
if len(str(target.reserved_address)) > 0:
check_addr = target.reserved_address
if ConfidentialAddress.valid(check_addr):
if isinstance(check_addr, ConfidentialAddress):
check_addr = check_addr.address
else:
check_addr = ConfidentialAddress.parse(
check_addr).address
if not isinstance(check_addr, Address):
check_addr = AddressUtil.parse(check_addr)
temp_network = Network.get(check_addr.network)
if temp_network in [Network.LIQUID_V1,
Network.ELEMENTS_REGTEST]:
network = temp_network.value
break

with util.create_handle() as handle:
work_handle = util.call_func(
'CfdInitializeFundRawTx', handle.get_handle(),
self.NETWORK, len(target_list), str(fee_asset))
network, len(target_list), str(fee_asset))
with JobHandle(handle, work_handle,
'CfdFreeFundRawTxHandle') as tx_handle:
for utxo in txin_utxo_list:
Expand Down
13 changes: 12 additions & 1 deletion cfd/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,10 +1085,21 @@ def set_opt(handle, tx_handle, key, i_val=0, f_val=0, b_val=False):
tx_handle.get_handle(), int(key.value),
int(i_val), float(f_val), b_val)

network = self.NETWORK
if len(str(reserved_address)) > 0:
if isinstance(reserved_address, Address):
check_addr = reserved_address
else:
check_addr = AddressUtil.parse(reserved_address)
temp_network = Network.get(check_addr.network)
if temp_network in [Network.MAINNET,
Network.TESTNET, Network.REGTEST]:
network = temp_network.value

with util.create_handle() as handle:
word_handle = util.call_func(
'CfdInitializeFundRawTx', handle.get_handle(),
self.NETWORK, 1, '')
network, 1, '')
with JobHandle(handle, word_handle,
'CfdFreeFundRawTxHandle') as tx_handle:
for utxo in txin_utxo_list:
Expand Down
44 changes: 44 additions & 0 deletions tests/data/bitcoin_coin_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,50 @@
],
"feeAmount": 7460
}
},
{
"case": "regtest address",
"request": {
"utxoFile": "utxo_3",
"selectUtxos": [],
"tx": "02000000000280969800000000001600144352a1a6e86311f22274f7ebb2746de21b09b15d00093d00000000001600148beaaac4654cf4ebd8e46ca5062b0e7fb3e7470c00000000",
"network": "regtest",
"targetAmount": 0,
"reserveAddress": "bcrt1q0r4elskfu8xlvvlvkergtzagv2ep8p9tfkvkm6",
"feeInfo": {
"feeRate": 20.0,
"longTermFeeRate": 20.0,
"knapsackMinChange": -1,
"dustFeeRate": 3.0
}
},
"expect": {
"hex": "02000000010af4768e14f820cb9063f55833b5999119e53390ecf4bf181842909b11d0974d0000000000ffffffff0380969800000000001600144352a1a6e86311f22274f7ebb2746de21b09b15d00093d00000000001600148beaaac4654cf4ebd8e46ca5062b0e7fb3e7470ce47f19000000000016001478eb9fc2c9e1cdf633ecb646858ba862b21384ab00000000",
"usedAddresses": [
"bcrt1q0r4elskfu8xlvvlvkergtzagv2ep8p9tfkvkm6"
],
"feeAmount": 3860
}
},
{
"case": "error: liquid address",
"request": {
"utxoFile": "utxo_3",
"selectUtxos": [],
"tx": "02000000000280969800000000001600144352a1a6e86311f22274f7ebb2746de21b09b15d00093d00000000001600148beaaac4654cf4ebd8e46ca5062b0e7fb3e7470c00000000",
"network": "regtest",
"targetAmount": 0,
"reserveAddress": "ert1q0r4elskfu8xlvvlvkergtzagv2ep8p9t3zeg96",
"feeInfo": {
"feeRate": 20.0,
"longTermFeeRate": 20.0,
"knapsackMinChange": -1,
"dustFeeRate": 3.0
}
},
"error": {
"cfd": "Base58 decode error."
}
}
]
}
Expand Down
146 changes: 146 additions & 0 deletions tests/data/elements_coin_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,152 @@
],
"feeAmount": 883
}
},
{
"case": "regtest address",
"request": {
"utxoFile": "elements_utxo_3",
"selectUtxos": [],
"tx": "020000000000020100000000000000000000000000000000000000000000000000000000000000aa010000000000989680001600144352a1a6e86311f22274f7ebb2746de21b09b15d0100000000000000000000000000000000000000000000000000000000000000bb01000000000007a120001600148beaaac4654cf4ebd8e46ca5062b0e7fb3e7470c00000000",
"network": "liquidv1",
"targets": [
{
"asset": "aa00000000000000000000000000000000000000000000000000000000000000",
"amount": 0,
"reservedAddress": "ert1q0r4elskfu8xlvvlvkergtzagv2ep8p9t3zeg96"
},
{
"asset": "bb00000000000000000000000000000000000000000000000000000000000000",
"amount": 0,
"reservedAddress": "ert1q55a7gqgnhdg09w9j6zl7585z8e6kx26lum2leh"
}
],
"feeInfo": {
"feeRate": 0.1,
"longTermFeeRate": 0.1,
"knapsackMinChange": -1,
"dustFeeRate": 3.0,
"feeAsset": "aa00000000000000000000000000000000000000000000000000000000000000",
"isBlindEstimateFee": true,
"exponent": 0,
"minimumBits": 52
}
},
"expect": {
"hex": "0200000000020bfa8774c5f753ce2f801a8106413b470af94edbff5b4242ed4c5a26d20e72b90000000000ffffffff040b0000000000000000000000000000000000000000000000000000000000000000000000ffffffff050100000000000000000000000000000000000000000000000000000000000000aa010000000000989680001600144352a1a6e86311f22274f7ebb2746de21b09b15d0100000000000000000000000000000000000000000000000000000000000000bb01000000000007a120001600148beaaac4654cf4ebd8e46ca5062b0e7fb3e7470c0100000000000000000000000000000000000000000000000000000000000000aa0100000000000001ff00000100000000000000000000000000000000000000000000000000000000000000bb010000000001124c1e00160014a53be40113bb50f2b8b2d0bfea1e823e75632b5f0100000000000000000000000000000000000000000000000000000000000000aa0100000000004b595f0016001478eb9fc2c9e1cdf633ecb646858ba862b21384ab00000000",
"usedAddresses": [
"ert1q0r4elskfu8xlvvlvkergtzagv2ep8p9t3zeg96",
"ert1q55a7gqgnhdg09w9j6zl7585z8e6kx26lum2leh"
],
"feeAmount": 511
}
},
{
"case": "confidential address",
"request": {
"utxoFile": "elements_utxo_3",
"selectUtxos": [],
"tx": "020000000000020100000000000000000000000000000000000000000000000000000000000000aa010000000000989680001600144352a1a6e86311f22274f7ebb2746de21b09b15d0100000000000000000000000000000000000000000000000000000000000000bb01000000000007a120001600148beaaac4654cf4ebd8e46ca5062b0e7fb3e7470c00000000",
"network": "liquidv1",
"targets": [
{
"asset": "aa00000000000000000000000000000000000000000000000000000000000000",
"amount": 0,
"reservedAddress": "el1qqdqg9pua7svrx9u5ujj4hp7djnfdy0837g42quyp4g5tj8pgkhj6z78tnlpvncwd7ce7edjxsk96sc4jzwz2ky5z0zegze59c"
},
{
"asset": "bb00000000000000000000000000000000000000000000000000000000000000",
"amount": 0,
"reservedAddress": "ert1q55a7gqgnhdg09w9j6zl7585z8e6kx26lum2leh"
}
],
"feeInfo": {
"feeRate": 0.1,
"longTermFeeRate": 0.1,
"knapsackMinChange": -1,
"dustFeeRate": 3.0,
"feeAsset": "aa00000000000000000000000000000000000000000000000000000000000000",
"isBlindEstimateFee": true,
"exponent": 0,
"minimumBits": 52
}
},
"expect": {
"hex": "0200000000020bfa8774c5f753ce2f801a8106413b470af94edbff5b4242ed4c5a26d20e72b90000000000ffffffff040b0000000000000000000000000000000000000000000000000000000000000000000000ffffffff050100000000000000000000000000000000000000000000000000000000000000aa010000000000989680001600144352a1a6e86311f22274f7ebb2746de21b09b15d0100000000000000000000000000000000000000000000000000000000000000bb01000000000007a120001600148beaaac4654cf4ebd8e46ca5062b0e7fb3e7470c0100000000000000000000000000000000000000000000000000000000000000aa0100000000000001ff00000100000000000000000000000000000000000000000000000000000000000000bb010000000001124c1e00160014a53be40113bb50f2b8b2d0bfea1e823e75632b5f0100000000000000000000000000000000000000000000000000000000000000aa0100000000004b595f034082879df418331794e4a55b87cd94d2d23cf1f22aa07081aa28b91c28b5e5a116001478eb9fc2c9e1cdf633ecb646858ba862b21384ab00000000",
"usedAddresses": [
"el1qqdqg9pua7svrx9u5ujj4hp7djnfdy0837g42quyp4g5tj8pgkhj6z78tnlpvncwd7ce7edjxsk96sc4jzwz2ky5z0zegze59c",
"ert1q55a7gqgnhdg09w9j6zl7585z8e6kx26lum2leh"
],
"feeAmount": 511
}
},
{
"case": "unmatch address network type",
"request": {
"utxoFile": "elements_utxo_3",
"selectUtxos": [],
"tx": "020000000000020100000000000000000000000000000000000000000000000000000000000000aa010000000000989680001600144352a1a6e86311f22274f7ebb2746de21b09b15d0100000000000000000000000000000000000000000000000000000000000000bb01000000000007a120001600148beaaac4654cf4ebd8e46ca5062b0e7fb3e7470c00000000",
"network": "liquidv1",
"targets": [
{
"asset": "aa00000000000000000000000000000000000000000000000000000000000000",
"amount": 0,
"reservedAddress": "ex1q0r4elskfu8xlvvlvkergtzagv2ep8p9ttsns6q"
},
{
"asset": "bb00000000000000000000000000000000000000000000000000000000000000",
"amount": 0,
"reservedAddress": "ert1q0r4elskfu8xlvvlvkergtzagv2ep8p9t3zeg96"
}
],
"feeInfo": {
"feeRate": 0.1,
"longTermFeeRate": 0.1,
"knapsackMinChange": -1,
"dustFeeRate": 3.0,
"feeAsset": "aa00000000000000000000000000000000000000000000000000000000000000",
"isBlindEstimateFee": true,
"exponent": 0,
"minimumBits": 52
}
},
"error": {
"cfd": "Failed to FundRawTransaction. Input address and network is unmatch."
}
},
{
"case": "bitcoin address",
"request": {
"utxoFile": "elements_utxo_3",
"selectUtxos": [],
"tx": "020000000000020100000000000000000000000000000000000000000000000000000000000000aa010000000000989680001600144352a1a6e86311f22274f7ebb2746de21b09b15d0100000000000000000000000000000000000000000000000000000000000000bb01000000000007a120001600148beaaac4654cf4ebd8e46ca5062b0e7fb3e7470c00000000",
"network": "liquidv1",
"targets": [
{
"asset": "aa00000000000000000000000000000000000000000000000000000000000000",
"amount": 0,
"reservedAddress": "bc1q0r4elskfu8xlvvlvkergtzagv2ep8p9tpewghq"
},
{
"asset": "bb00000000000000000000000000000000000000000000000000000000000000",
"amount": 0,
"reservedAddress": "bc1q55a7gqgnhdg09w9j6zl7585z8e6kx26lvqaltd"
}
],
"feeInfo": {
"feeRate": 0.1,
"longTermFeeRate": 0.1,
"knapsackMinChange": -1,
"dustFeeRate": 3.0,
"feeAsset": "aa00000000000000000000000000000000000000000000000000000000000000",
"isBlindEstimateFee": true,
"exponent": 0,
"minimumBits": 52
}
},
"error": {
"cfd": "Base58 decode error."
}
}
]
}
Expand Down

0 comments on commit b8ec6e6

Please sign in to comment.