mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-23 22:15:44 +00:00
increased cc usage to 0.9.9 readded daemon proceses
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
9f66450c7c
commit
99e1edf880
@ -13,6 +13,6 @@ RUN pip install --upgrade \
|
||||
pycco \
|
||||
websocket-client~=0.47.0 \
|
||||
pytest~=3.0 \
|
||||
planetmint-cryptoconditions>=0.9.8\
|
||||
planetmint-cryptoconditions>=0.9.9\
|
||||
planetmint-driver>=0.9.2 \
|
||||
blns
|
||||
|
||||
@ -4,6 +4,7 @@ import base58
|
||||
from hashlib import sha3_256
|
||||
from cryptoconditions.types.ed25519 import Ed25519Sha256
|
||||
from cryptoconditions.types.zenroom import ZenroomSha256
|
||||
from zenroom import zencode_exec
|
||||
from planetmint_driver import Planetmint
|
||||
from planetmint_driver.crypto import generate_keypair
|
||||
|
||||
@ -18,13 +19,13 @@ def test_zenroom_signing(gen_key_zencode, secret_key_to_private_key_zencode,
|
||||
biolabs = generate_keypair()
|
||||
version = '2.0'
|
||||
|
||||
alice = json.loads(ZenroomSha256.run_zenroom(gen_key_zencode).output)['keyring']
|
||||
bob = json.loads(ZenroomSha256.run_zenroom(gen_key_zencode).output)['keyring']
|
||||
alice = json.loads(zencode_exec(gen_key_zencode).output)['keyring']
|
||||
bob = json.loads(zencode_exec(gen_key_zencode).output)['keyring']
|
||||
|
||||
zen_public_keys = json.loads(ZenroomSha256.run_zenroom(secret_key_to_private_key_zencode.format('Alice'),
|
||||
keys={'keyring': alice}).output)
|
||||
zen_public_keys.update(json.loads(ZenroomSha256.run_zenroom(secret_key_to_private_key_zencode.format('Bob'),
|
||||
keys={'keyring': bob}).output))
|
||||
zen_public_keys = json.loads(zencode_exec(secret_key_to_private_key_zencode.format('Alice'),
|
||||
keys=json.dumps({'keyring': alice})).output)
|
||||
zen_public_keys.update(json.loads(zencode_exec(secret_key_to_private_key_zencode.format('Bob'),
|
||||
keys=json.dumps({'keyring': bob})).output))
|
||||
|
||||
|
||||
|
||||
@ -54,10 +55,16 @@ def test_zenroom_signing(gen_key_zencode, secret_key_to_private_key_zencode,
|
||||
'fulfills': None,
|
||||
'owners_before': [biolabs.public_key,]
|
||||
}
|
||||
metadata = {
|
||||
"result": {
|
||||
"output": ["ok"]
|
||||
}
|
||||
}
|
||||
|
||||
token_creation_tx = {
|
||||
'operation': 'CREATE',
|
||||
'asset': zenroom_house_assets,
|
||||
'metadata': None,
|
||||
'metadata': metadata,
|
||||
'outputs': [output,],
|
||||
'inputs': [input_,],
|
||||
'version': version,
|
||||
|
||||
@ -15,6 +15,6 @@ RUN pip install --upgrade \
|
||||
pytest~=6.2.5 \
|
||||
pycco \
|
||||
websocket-client~=0.47.0 \
|
||||
planetmint-cryptoconditions>=0.9.8\
|
||||
planetmint-cryptoconditions>=0.9.9\
|
||||
planetmint-driver>=0.9.2 \
|
||||
blns
|
||||
|
||||
@ -4,66 +4,91 @@ from hashlib import sha3_256
|
||||
from cryptoconditions.types.zenroom import ZenroomSha256
|
||||
from planetmint_driver.crypto import generate_keypair
|
||||
from .helper.hosts import Hosts
|
||||
from zenroom import zencode_exec
|
||||
import time
|
||||
|
||||
def test_zenroom_signing(gen_key_zencode, secret_key_to_private_key_zencode,
|
||||
fulfill_script_zencode, zenroom_data, zenroom_house_assets,
|
||||
condition_script_zencode):
|
||||
|
||||
def test_zenroom_signing(
|
||||
gen_key_zencode,
|
||||
secret_key_to_private_key_zencode,
|
||||
fulfill_script_zencode,
|
||||
zenroom_data,
|
||||
zenroom_house_assets,
|
||||
condition_script_zencode,
|
||||
):
|
||||
|
||||
biolabs = generate_keypair()
|
||||
version = '2.0'
|
||||
version = "2.0"
|
||||
|
||||
alice = json.loads(ZenroomSha256.run_zenroom(gen_key_zencode).output)['keyring']
|
||||
bob = json.loads(ZenroomSha256.run_zenroom(gen_key_zencode).output)['keyring']
|
||||
alice = json.loads(zencode_exec(gen_key_zencode).output)["keyring"]
|
||||
bob = json.loads(zencode_exec(gen_key_zencode).output)["keyring"]
|
||||
|
||||
zen_public_keys = json.loads(ZenroomSha256.run_zenroom(secret_key_to_private_key_zencode.format('Alice'),
|
||||
keys={'keyring': alice}).output)
|
||||
zen_public_keys.update(json.loads(ZenroomSha256.run_zenroom(secret_key_to_private_key_zencode.format('Bob'),
|
||||
keys={'keyring': bob}).output))
|
||||
zen_public_keys = json.loads(
|
||||
ZenroomSha256.run_zenroom(
|
||||
secret_key_to_private_key_zencode.format("Alice"),
|
||||
keys=json.dumps({"keyring": alice}),
|
||||
).output
|
||||
)
|
||||
zen_public_keys.update(
|
||||
json.loads(
|
||||
ZenroomSha256.run_zenroom(
|
||||
secret_key_to_private_key_zencode.format("Bob"),
|
||||
keys=json.dumps({"keyring": bob}),
|
||||
).output
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
|
||||
zenroomscpt = ZenroomSha256(script=fulfill_script_zencode, data=zenroom_data, keys=zen_public_keys)
|
||||
print(F'zenroom is: {zenroomscpt.script}')
|
||||
zenroomscpt = ZenroomSha256(
|
||||
script=fulfill_script_zencode, data=zenroom_data, keys=zen_public_keys
|
||||
)
|
||||
print(f"zenroom is: {zenroomscpt.script}")
|
||||
|
||||
# CRYPTO-CONDITIONS: generate the condition uri
|
||||
condition_uri_zen = zenroomscpt.condition.serialize_uri()
|
||||
print(F'\nzenroom condition URI: {condition_uri_zen}')
|
||||
print(f"\nzenroom condition URI: {condition_uri_zen}")
|
||||
|
||||
# CRYPTO-CONDITIONS: construct an unsigned fulfillment dictionary
|
||||
unsigned_fulfillment_dict_zen = {
|
||||
'type': zenroomscpt.TYPE_NAME,
|
||||
'public_key': base58.b58encode(biolabs.public_key).decode(),
|
||||
"type": zenroomscpt.TYPE_NAME,
|
||||
"public_key": base58.b58encode(biolabs.public_key).decode(),
|
||||
}
|
||||
output = {
|
||||
'amount': '10',
|
||||
'condition': {
|
||||
'details': unsigned_fulfillment_dict_zen,
|
||||
'uri': condition_uri_zen,
|
||||
|
||||
"amount": "10",
|
||||
"condition": {
|
||||
"details": unsigned_fulfillment_dict_zen,
|
||||
"uri": condition_uri_zen,
|
||||
},
|
||||
'public_keys': [biolabs.public_key,],
|
||||
"public_keys": [
|
||||
biolabs.public_key,
|
||||
],
|
||||
}
|
||||
input_ = {
|
||||
'fulfillment': None,
|
||||
'fulfills': None,
|
||||
'owners_before': [biolabs.public_key,]
|
||||
"fulfillment": None,
|
||||
"fulfills": None,
|
||||
"owners_before": [
|
||||
biolabs.public_key,
|
||||
],
|
||||
}
|
||||
metadata = {"result": {"output": ["ok"]}}
|
||||
token_creation_tx = {
|
||||
'operation': 'CREATE',
|
||||
'asset': zenroom_house_assets,
|
||||
'metadata': None,
|
||||
'outputs': [output,],
|
||||
'inputs': [input_,],
|
||||
'version': version,
|
||||
'id': None,
|
||||
"operation": "CREATE",
|
||||
"asset": zenroom_house_assets,
|
||||
"metadata": metadata,
|
||||
"outputs": [
|
||||
output,
|
||||
],
|
||||
"inputs": [
|
||||
input_,
|
||||
],
|
||||
"version": version,
|
||||
"id": None,
|
||||
}
|
||||
|
||||
# JSON: serialize the transaction-without-id to a json formatted string
|
||||
message = json.dumps(
|
||||
token_creation_tx,
|
||||
sort_keys=True,
|
||||
separators=(',', ':'),
|
||||
separators=(",", ":"),
|
||||
ensure_ascii=False,
|
||||
)
|
||||
|
||||
@ -73,31 +98,23 @@ def test_zenroom_signing(gen_key_zencode, secret_key_to_private_key_zencode,
|
||||
#
|
||||
# the server should ick the fulfill script and recreate the zenroom-sha and verify the signature
|
||||
|
||||
|
||||
|
||||
message = zenroomscpt.sign(message, condition_script_zencode, alice)
|
||||
assert(zenroomscpt.validate(message=message))
|
||||
assert zenroomscpt.validate(message=message)
|
||||
|
||||
message = json.loads(message)
|
||||
fulfillment_uri_zen = zenroomscpt.serialize_uri()
|
||||
|
||||
message['inputs'][0]['fulfillment'] = fulfillment_uri_zen
|
||||
message["inputs"][0]["fulfillment"] = fulfillment_uri_zen
|
||||
tx = message
|
||||
tx['id'] = None
|
||||
json_str_tx = json.dumps(
|
||||
tx,
|
||||
sort_keys=True,
|
||||
skipkeys=False,
|
||||
separators=(',', ':')
|
||||
)
|
||||
tx["id"] = None
|
||||
json_str_tx = json.dumps(tx, sort_keys=True, skipkeys=False, separators=(",", ":"))
|
||||
# SHA3: hash the serialized id-less transaction to generate the id
|
||||
shared_creation_txid = sha3_256(json_str_tx.encode()).hexdigest()
|
||||
message['id'] = shared_creation_txid
|
||||
message["id"] = shared_creation_txid
|
||||
|
||||
hosts = Hosts('/shared/hostnames')
|
||||
hosts = Hosts("/shared/hostnames")
|
||||
pm_alpha = hosts.get_connection()
|
||||
|
||||
|
||||
sent_transfer_tx = pm_alpha.transactions.send_commit(message)
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
@ -36,26 +36,29 @@ BANNER = """
|
||||
|
||||
def start(args):
|
||||
# Exchange object for event stream api
|
||||
logger.info('Starting Planetmint')
|
||||
logger.info("Starting Planetmint")
|
||||
exchange = Exchange()
|
||||
# start the web api
|
||||
app_server = server.create_server(
|
||||
settings=planetmint.config['server'],
|
||||
log_config=planetmint.config['log'],
|
||||
planetmint_factory=Planetmint)
|
||||
p_webapi = Process(name='planetmint_webapi', target=app_server.run, daemon=False)
|
||||
settings=planetmint.config["server"],
|
||||
log_config=planetmint.config["log"],
|
||||
planetmint_factory=Planetmint,
|
||||
)
|
||||
p_webapi = Process(name="planetmint_webapi", target=app_server.run, daemon=True)
|
||||
p_webapi.start()
|
||||
|
||||
logger.info(BANNER.format(planetmint.config['server']['bind']))
|
||||
logger.info(BANNER.format(planetmint.config["server"]["bind"]))
|
||||
|
||||
# start websocket server
|
||||
p_websocket_server = Process(name='planetmint_ws',
|
||||
p_websocket_server = Process(
|
||||
name="planetmint_ws",
|
||||
target=websocket_server.start,
|
||||
daemon=True,
|
||||
args=(exchange.get_subscriber_queue(EventTypes.BLOCK_VALID),))
|
||||
args=(exchange.get_subscriber_queue(EventTypes.BLOCK_VALID),),
|
||||
)
|
||||
p_websocket_server.start()
|
||||
|
||||
p_exchange = Process(name='planetmint_exchange', target=exchange.run, daemon=True)
|
||||
p_exchange = Process(name="planetmint_exchange", target=exchange.run, daemon=True)
|
||||
p_exchange.start()
|
||||
|
||||
# We need to import this after spawning the web server
|
||||
@ -63,7 +66,7 @@ def start(args):
|
||||
# for gevent.
|
||||
from abci.server import ABCIServer
|
||||
|
||||
setproctitle.setproctitle('planetmint')
|
||||
setproctitle.setproctitle("planetmint")
|
||||
|
||||
# Start the ABCIServer
|
||||
# abci = ABCI(TmVersion(planetmint.config['tendermint']['version']))
|
||||
@ -82,5 +85,5 @@ def start(args):
|
||||
app.run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
start()
|
||||
|
||||
2
setup.py
2
setup.py
@ -73,7 +73,7 @@ install_requires = [
|
||||
"chardet==3.0.4",
|
||||
"aiohttp==3.8.1",
|
||||
"abci==0.8.3",
|
||||
"planetmint-cryptoconditions>=0.9.8",
|
||||
"planetmint-cryptoconditions>=0.9.9",
|
||||
"flask-cors==3.0.10",
|
||||
"flask-restful==0.3.9",
|
||||
"flask==2.0.1",
|
||||
|
||||
@ -2,6 +2,7 @@ import pytest
|
||||
import json
|
||||
import base58
|
||||
from hashlib import sha3_256
|
||||
from zenroom import zencode_exec
|
||||
from cryptoconditions.types.ed25519 import Ed25519Sha256
|
||||
from cryptoconditions.types.zenroom import ZenroomSha256
|
||||
from planetmint.transactions.common.crypto import generate_key_pair
|
||||
@ -59,18 +60,18 @@ def test_zenroom_signing():
|
||||
biolabs = generate_key_pair()
|
||||
version = "2.0"
|
||||
|
||||
alice = json.loads(ZenroomSha256.run_zenroom(GENERATE_KEYPAIR).output)["keyring"]
|
||||
bob = json.loads(ZenroomSha256.run_zenroom(GENERATE_KEYPAIR).output)["keyring"]
|
||||
alice = json.loads(zencode_exec(GENERATE_KEYPAIR).output)["keyring"]
|
||||
bob = json.loads(zencode_exec(GENERATE_KEYPAIR).output)["keyring"]
|
||||
|
||||
zen_public_keys = json.loads(
|
||||
ZenroomSha256.run_zenroom(
|
||||
SK_TO_PK.format("Alice"), keys={"keyring": alice}
|
||||
zencode_exec(
|
||||
SK_TO_PK.format("Alice"), keys=json.dumps({"keyring": alice})
|
||||
).output
|
||||
)
|
||||
zen_public_keys.update(
|
||||
json.loads(
|
||||
ZenroomSha256.run_zenroom(
|
||||
SK_TO_PK.format("Bob"), keys={"keyring": bob}
|
||||
zencode_exec(
|
||||
SK_TO_PK.format("Bob"), keys=json.dumps({"keyring": bob})
|
||||
).output
|
||||
)
|
||||
)
|
||||
@ -106,10 +107,15 @@ def test_zenroom_signing():
|
||||
biolabs.public_key,
|
||||
],
|
||||
}
|
||||
metadata = {
|
||||
"result": {
|
||||
"output": ["ok"]
|
||||
}
|
||||
}
|
||||
token_creation_tx = {
|
||||
"operation": "CREATE",
|
||||
"asset": HOUSE_ASSETS,
|
||||
"metadata": None,
|
||||
"metadata": metadata,
|
||||
"outputs": [
|
||||
output,
|
||||
],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user