Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion protos
37 changes: 9 additions & 28 deletions remme/clients/node_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from remme.protos.node_account_pb2 import (
NodeAccount, NodeAccountMethod, NodeAccountInternalTransferPayload
)
from remme.protos.transaction_pb2 import EmptyPayload
from remme.clients.basic import BasicClient
from remme.tp.node_account import NodeAccountHandler
from remme.protos.transaction_pb2 import TransactionPayload
Expand All @@ -28,17 +29,14 @@
class NodeAccountClient(BasicClient):

NODE_ACCOUNT_GENESIS_BATCH = '/genesis/batch/node-proposal.batch'
NODE_ACCOUNT_TO_MN_BATCH = '/genesis/batch/n2mn-proposal.batch'

def __init__(self):
super().__init__(NodeAccountHandler)

@classmethod
def get_internal_transfer_payload(self, value):
transfer = NodeAccountInternalTransferPayload()
transfer.value = value

return transfer
@staticmethod
def get_empty_payload():
payload = EmptyPayload()
return payload

async def get_account(self, address):
account = NodeAccount()
Expand All @@ -48,37 +46,20 @@ async def get_account(self, address):

def generate_genesis_batches(self):
self._generate_genesis_node_account_batch()
self._generate_master_node_batch()

def _generate_genesis_node_account_batch(self):
addresses_input = [
self.get_signer_address(),
_make_settings_key(SETTINGS_GENESIS_OWNERS)
_make_settings_key(SETTINGS_GENESIS_OWNERS),
NODE_STATE_ADDRESS
]
addresses_output = addresses_input

payload = TransactionPayload()
payload.method = NodeAccountMethod.INITIALIZE_NODE
payload.data = self.get_internal_transfer_payload(250000).SerializeToString()
payload.method = NodeAccountMethod.GENESIS
payload.data = self.get_empty_payload().SerializeToString()

return self._write_batch_to_file(self.NODE_ACCOUNT_GENESIS_BATCH,
payload,
addresses_input,
addresses_output)

def _generate_master_node_batch(self):
addresses_input = [
self.get_signer_address(),
NODE_STATE_ADDRESS,
_make_settings_key(SETTINGS_MINIMUM_STAKE)
]
addresses_output = addresses_input

payload = TransactionPayload()
payload.method = NodeAccountMethod.INITIALIZE_MASTERNODE
payload.data = self.get_internal_transfer_payload(250000).SerializeToString()

return self._write_batch_to_file(self.NODE_ACCOUNT_TO_MN_BATCH,
payload,
addresses_input,
addresses_output)
1 change: 0 additions & 1 deletion remme/shared/forms/atomic_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class AtomicSwapInitPayloadForm(ProtoForm):
swap_id = SwapIDField()
secret_lock_by_solicitor = fields.StringField(validators=[validators.Optional()])
email_address_encrypted_by_initiator = fields.StringField(validators=[validators.Optional()])
created_at = fields.IntegerField(validators=[validators.DataRequired()])


class AtomicSwapApprovePayloadForm(ProtoForm):
Expand Down
52 changes: 43 additions & 9 deletions remme/tp/node_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,16 @@ def get_state_processor(self):
VALIDATOR: NodeAccountInternalTransferPayloadForm,
FEE_AUTO_CHARGER: True,
},
NodeAccountMethod.GENESIS: {
PB_CLASS: EmptyPayload,
PROCESSOR: self._genesis,
VALIDATOR: ProtoForm,
FEE_AUTO_CHARGER: None,
},
NodeAccountMethod.INITIALIZE_NODE: {
PB_CLASS: NodeAccountInternalTransferPayload,
PB_CLASS: EmptyPayload,
PROCESSOR: self._initialize_node,
VALIDATOR: NodeAccountGenesisForm,
VALIDATOR: ProtoForm,
FEE_AUTO_CHARGER: None,
},
NodeAccountMethod.INITIALIZE_MASTERNODE: {
Expand Down Expand Up @@ -110,19 +116,47 @@ def get_state_processor(self):
},
}

def _initialize_node(self, context, node_account_public_key, internal_transfer_payload):
def _genesis(self, context, node_account_public_key, empty_payload):
node_account_address = self.make_address_from_data(node_account_public_key)

genesis_owners = _get_setting_value(context, SETTINGS_GENESIS_OWNERS)
genesis_owners = genesis_owners.split(',') if genesis_owners is not None else []
if node_account_public_key not in genesis_owners:
raise InvalidTransaction('Not allowed to perform this operation.')

node_account, node_state = get_multiple_data(context, [
(node_account_address, NodeAccount),
(NODE_STATE_ADDRESS, NodeState),
])

if node_account is not None:
raise InvalidTransaction('Node account already exists.')

node_account = NodeAccount(min=True, node_state=NodeAccount.OPENED)

LOGGER.info(f"Node account \"{node_account_address}\" created")

if node_state is None:
node_state = NodeState()

if node_account_address not in node_state.master_nodes:
node_state.master_nodes.append(node_account_address)

return {
node_account_address: node_account,
NODE_STATE_ADDRESS: node_state,
}

def _initialize_node(self, context, node_account_public_key, empty_payload):
node_account_address = self.make_address_from_data(node_account_public_key)

node_account = get_data(context, NodeAccount, node_account_address)

if node_account is None:
node_account = NodeAccount(
balance=client_to_real_amount(internal_transfer_payload.value),
min=True,
)
else:
if node_account is not None:
raise InvalidTransaction('Node account already exists.')

node_account = NodeAccount(min=True)

LOGGER.info(f"Node account \"{node_account_address}\" created")

return {
Expand Down
3 changes: 0 additions & 3 deletions scripts/node/validator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ if [ "$REMME_START_MODE" = "genesis" ]; then
echo "Writing batch for node account genesis..."
GENESIS_BATCHES="$GENESIS_BATCHES /genesis/batch/node-proposal.batch"

echo "Writing batch for node 2 master node convertion genesis..."
GENESIS_BATCHES="$GENESIS_BATCHES /genesis/batch/n2mn-proposal.batch"

echo "Writing batch for consensus account genesis..."
GENESIS_BATCHES="$GENESIS_BATCHES /genesis/batch/consensus-proposal.batch"

Expand Down
6 changes: 0 additions & 6 deletions testing/unit/tp/atomic_swap/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ def test_atomic_swap_init_with_empty_proto():
'sender_address_non_local': ['This field is required.'],
'amount': ['This field is required.'],
'swap_id': ['Missed swap_id.'],
'created_at': ['This field is required.'],
}
) == str(error.value)

Expand All @@ -169,7 +168,6 @@ def test_atomic_swap_init():
swap_id=SWAP_ID,
secret_lock_by_solicitor=BOT_IT_IS_INITIATOR_MARK,
email_address_encrypted_by_initiator=ALICE_EMAIL_ADDRESS_ENCRYPTED_BY_INITIATOR,
created_at=CURRENT_TIMESTAMP,
)

transaction_payload = TransactionPayload()
Expand Down Expand Up @@ -280,7 +278,6 @@ def test_atomic_swap_init_already_taken_id():
swap_id=SWAP_ID,
secret_lock_by_solicitor=BOT_IT_IS_INITIATOR_MARK,
email_address_encrypted_by_initiator=ALICE_EMAIL_ADDRESS_ENCRYPTED_BY_INITIATOR,
created_at=CURRENT_TIMESTAMP,
)

transaction_payload = TransactionPayload()
Expand Down Expand Up @@ -343,7 +340,6 @@ def test_atomic_swap_init_swap_no_block_config_info():
swap_id=SWAP_ID,
secret_lock_by_solicitor=BOT_IT_IS_INITIATOR_MARK,
email_address_encrypted_by_initiator=ALICE_EMAIL_ADDRESS_ENCRYPTED_BY_INITIATOR,
created_at=CURRENT_TIMESTAMP,
)

transaction_payload = TransactionPayload()
Expand Down Expand Up @@ -393,7 +389,6 @@ def test_atomic_swap_init_swap_no_block_info():
swap_id=SWAP_ID,
secret_lock_by_solicitor=BOT_IT_IS_INITIATOR_MARK,
email_address_encrypted_by_initiator=ALICE_EMAIL_ADDRESS_ENCRYPTED_BY_INITIATOR,
created_at=CURRENT_TIMESTAMP,
)

transaction_payload = TransactionPayload()
Expand Down Expand Up @@ -446,7 +441,6 @@ def test_atomic_swap_init_swap_receiver_address_invalid_type():
swap_id=SWAP_ID,
secret_lock_by_solicitor=BOT_IT_IS_INITIATOR_MARK,
email_address_encrypted_by_initiator=ALICE_EMAIL_ADDRESS_ENCRYPTED_BY_INITIATOR,
created_at=CURRENT_TIMESTAMP,
)

transaction_payload = TransactionPayload()
Expand Down