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