本文整理汇总了Python中btctxstore.BtcTxStore类的典型用法代码示例。如果您正苦于以下问题:Python BtcTxStore类的具体用法?Python BtcTxStore怎么用?Python BtcTxStore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BtcTxStore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
self.testnet_api = BtcTxStore(dryrun=True, testnet=True)
self.mainnet_api = BtcTxStore(dryrun=True, testnet=False)
self.testnet_wallet = self.testnet_api.create_wallet()
self.mainnet_wallet = self.mainnet_api.create_wallet()
self.testnet_key = self.testnet_api.get_key(self.testnet_wallet)
self.mainnet_key = self.mainnet_api.get_key(self.mainnet_wallet)
示例2: _setup_data_transfer_client
def _setup_data_transfer_client(self, store_config, passive_port,
passive_bind, node_type, nat_type, wan_ip):
# Setup handlers for callbacks registered via the API.
handlers = {
"complete": self._transfer_complete_handlers,
"accept": self._transfer_request_handlers
}
wallet = BtcTxStore(testnet=False, dryrun=True)
wif = self.get_key()
node_id = address_to_node_id(wallet.get_address(wif))
#dht_node = SimDHT(node_id=node_id)
dht_node = self
self._data_transfer = FileTransfer(
net=Net(
net_type="direct",
node_type=node_type,
nat_type=nat_type,
dht_node=dht_node,
debug=1,
passive_port=passive_port,
passive_bind=passive_bind,
wan_ip=wan_ip
),
wif=wif,
store_config=store_config,
handlers=handlers
)
# Setup success callback values.
self._data_transfer.success_value = (self.sync_get_wan_ip(), self.port)
self.process_data_transfers()
示例3: test_together_sender_key_and_btctx_api
def test_together_sender_key_and_btctx_api(self):
"""
Test of possibility to provide the ``sender_key`` and ``btctx_api``
only together.
"""
btctx_api = BtcTxStore(testnet=True, dryrun=True)
sender_key = btctx_api.create_key()
self.mock_get.return_value = Response()
# test only "sender_key" given
self.assertRaises(
TypeError,
core.download,
*(self.test_url_address, self.file_hash),
**{'sender_key': sender_key}
)
# test only "btctx_api" given
self.assertRaises(
TypeError,
core.download,
*(self.test_url_address, self.file_hash),
**{'btctx_api': btctx_api}
)
# test of now exception when both args are given
download_call_result = core.download(
self.test_url_address,
self.file_hash,
sender_key=sender_key,
btctx_api=btctx_api
)
self.assertIsInstance(download_call_result, Response,
'Must return a response object')
示例4: test_core_audit
def test_core_audit(self):
"""
Test of providing correct arguments to the ``requests.post()``
and returning gotten response object.
"""
test_url_address = 'http://test.url.com'
file_hash = sha256(b'some test data').hexdigest()
seed = sha256(b'some test challenge seed').hexdigest()
btctx_api = BtcTxStore(testnet=True, dryrun=True)
sender_key = btctx_api.create_key()
audit_call_result = core.audit(test_url_address, sender_key,
btctx_api, file_hash, seed)
expected_calls = [call(
urljoin(test_url_address, '/api/audit/'),
data={
'data_hash': file_hash,
'challenge_seed': seed,
},
headers={
'sender-address': btctx_api.get_address(sender_key),
'signature': btctx_api.sign_unicode(sender_key, file_hash),
}
)]
self.assertListEqual(
self.mock_post.call_args_list,
expected_calls,
'In the audit() function requests.post() calls are unexpected'
)
self.assertIs(
self.mock_post.return_value,
audit_call_result,
'Returned value must be the object returned by the '
'``requests.post()``'
)
示例5: test_authenticate_headers_provide
def test_authenticate_headers_provide(self):
"""
Test of preparing and providing credential headers when ``sender_key``
and ``btctx_api`` are provided.
"""
btctx_api = BtcTxStore(testnet=True, dryrun=True)
sender_key = btctx_api.create_key()
signature = btctx_api.sign_unicode(sender_key, self.file_hash)
sender_address = btctx_api.get_address(sender_key)
self.mock_get.return_value = Response()
self.test_data_for_requests['headers'] = {
'sender-address': sender_address,
'signature': signature,
}
download_call_result = core.download(
self.test_url_address,
self.file_hash,
sender_key=sender_key,
btctx_api=btctx_api
)
expected_mock_calls = [call(
urljoin(self.test_url_address, '/api/files/' + self.file_hash),
**self.test_data_for_requests
)]
self.assertListEqual(
self.mock_get.call_args_list,
expected_mock_calls,
'In the download() function requests.get() calls are unexpected'
)
self.assertIsInstance(download_call_result, Response,
'Must return a response object')
示例6: setUp
def setUp(self):
# Create a temporary that will be used as uploaded file.
self.testing_dir = os.path.dirname(os.path.abspath(__file__))
self.test_source_file = tempfile.NamedTemporaryFile(
prefix='tmp_',
suffix='.spam',
mode="w+",
dir=self.testing_dir,
)
self.test_source_file.write('some file content')
self.test_source_file.flush()
# Mock the ``requests`` package.
self.post_patch = patch('requests.post')
self.mock_post = self.post_patch.start()
self.mock_post.return_value = Response()
# Prepare common arguments for the API's ``upload()`` function call.
btctx_api = BtcTxStore(testnet=True, dryrun=True)
self.upload_param = dict(
url_base='http://test.url.com',
btctx_api=btctx_api,
sender_key=btctx_api.create_key(),
file_role='101',
)
示例7: generate_block
def generate_block(self):
"""Close the current block, and generate a new one."""
try:
last_block = latest_block(self.conn)
last_hash = latest_hash(self.conn)
# Get Merkle Root
self.find_leaves()
self.close()
merkle_root = self.merkle_root()
# Get TXID
blockchain = BtcTxStore()
hexdata = merkle_root
privatekeys = app.config["PRIVATE_KEYS"]
changeaddress = app.config["CHANGE_ADDRESS"]
tx_id = blockchain.store(hexdata, privatekeys, changeaddress)
# Close current block
c = self.conn.cursor()
query1 = "UPDATE block_table SET end_hash=?, closed=?, merkle_root=?, tx_id=? WHERE id=?"
c.execute(query1, (last_hash, True, merkle_root, tx_id, last_block))
# Start new block
query2 = "INSERT INTO block_table (start_hash) VALUES (?)"
c.execute(query2, (last_hash,))
self.conn.commit()
self.conn.close()
return 'Block {0} Built.'.format(last_block)
except LookupError:
return 'Block Empty.'
示例8: args_prepare
def args_prepare(required_args, parsed_args):
"""
Filling all missed, but required by the core API function arguments.
Return dictionary that will be passed to the API function.
:param required_args: list of required argument's names for
the API function
:type required_args: list of stings
:param parsed_args: can be any object with appropriate names of attributes
required by the core API function
:type parsed_args: argparse.Namespace
:returns: dictionary that will be used like the ``**kwargs`` argument
:rtype: dictionary
"""
prepared_args = {}
if 'sender_key' in required_args and 'btctx_api' in required_args:
btctx_api = BtcTxStore(testnet=True, dryrun=True)
args_base = dict(
sender_key=btctx_api.create_key(),
btctx_api=btctx_api,
)
for required_arg in required_args:
try:
prepared_args[required_arg] = getattr(parsed_args, required_arg)
except AttributeError:
prepared_args[required_arg] = args_base[required_arg]
return prepared_args
示例9: test_fail
def test_fail(self):
# register without auth headres fails
rv = self.app.get('/api/register/{0}'.format(addresses["eta"]))
self.assertEqual(rv.status_code, 401)
# register first because ping is lazy
blockchain = BtcTxStore()
wif = blockchain.create_key()
address = blockchain.get_address(wif)
header_date = formatdate(timeval=mktime(datetime.now().timetuple()),
localtime=True, usegmt=True)
message = app.config["ADDRESS"] + " " + header_date
header_authorization = blockchain.sign_unicode(wif, message)
headers = {"Date": header_date, "Authorization": header_authorization}
url = '/api/register/{0}'.format(address)
rv = self.app.get(url, headers=headers)
self.assertEqual(rv.status_code, 200)
# ping without auth headres fails
time.sleep(app.config["MAX_PING"])
rv = self.app.get('/api/ping/{0}'.format(address))
self.assertEqual(rv.status_code, 401)
# set height without auth headres fails
rv = self.app.get('/api/height/{0}/10'.format(addresses["eta"]))
self.assertEqual(rv.status_code, 401)
示例10: callback
def callback():
blockchain = BtcTxStore()
wif = blockchain.create_key()
address = blockchain.get_address(wif)
farmer = Farmer(address)
header_date = formatdate(timeval=mktime(datetime.now().timetuple()),
localtime=True, usegmt=True)
header_authorization = blockchain.sign_unicode(wif, "lalala-wrong")
farmer.authenticate(header_authorization, header_date)
示例11: test_authentication_success
def test_authentication_success(self):
blockchain = BtcTxStore()
wif = blockchain.create_key()
address = blockchain.get_address(wif)
farmer = Farmer(address)
header_date = formatdate(timeval=mktime(datetime.now().timetuple()),
localtime=True, usegmt=True)
message = farmer.get_server_address() + " " + header_date
header_authorization = blockchain.sign_unicode(wif, message)
self.assertTrue(farmer.authenticate(header_authorization, header_date))
示例12: callback
def callback():
blockchain = BtcTxStore()
wif = blockchain.create_key()
address = blockchain.get_address(wif)
farmer = Farmer(address)
header_date = formatdate(timeval=mktime(datetime.now().timetuple())
, localtime=True, usegmt=True)
message = farmer.get_server_address() + " " + header_date
header_authorization = blockchain.sign_unicode(wif, message)
headers = {"Date": None, "Authorization": header_authorization}
farmer.authenticate(headers)
示例13: callback
def callback():
blockchain = BtcTxStore()
wif = blockchain.create_key()
address = blockchain.get_address(wif)
farmer = Farmer(address)
timeout = farmer.get_server_authentication_timeout()
date = datetime.now() - timedelta(seconds=timeout)
header_date = formatdate(timeval=mktime(date.timetuple()),
localtime=True, usegmt=True)
message = farmer.get_server_address() + " " + header_date
header_authorization = blockchain.sign_unicode(wif, message)
farmer.authenticate(header_authorization, header_date)
示例14: TestSignTx
class TestSignTx(unittest.TestCase):
def setUp(self):
self.api = BtcTxStore(dryrun=True, testnet=True)
def test_signtx(self):
txins = fixtures["signtx"]["txins"]
txouts = fixtures["signtx"]["txouts"]
wifs = fixtures["signtx"]["wifs"]
expected = fixtures["signtx"]["expected"]
rawtx = self.api.createtx(txins, txouts)
rawtx = self.api.addnulldata(rawtx, "f483")
result = self.api.signtx(rawtx, wifs)
self.assertEqual(result, expected)
示例15: TestConfirms
class TestConfirms(unittest.TestCase):
def setUp(self):
self.api = BtcTxStore(dryrun=True, testnet=False)
def test_confirmed(self):
confirms = self.api.confirms(CONFIRMED)
self.assertGreater(confirms, 0)
def test_unconfirmed(self):
pass # TODO find always unconfirmed tx and test
def test_unpublished(self):
confirms = self.api.confirms(UNPUBLISHED)
self.assertIsNone(confirms)