-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #280 from xian-network/genesis-rc
genesis block for rcnet
- Loading branch information
Showing
6 changed files
with
581 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"extension": ".s.py", | ||
"contracts": [ | ||
{ | ||
"name": "currency", | ||
"owner": null, | ||
"constructor_args": { | ||
"vk": "13ca9a62d10cbc28d55408e0a85d31f5c059fe3bb49316538e1d03064f3f2c8e" | ||
} | ||
}, | ||
{ | ||
"name": "stamp_cost", | ||
"owner": "masternodes", | ||
"constructor_args": { | ||
"initial_rate": 20 | ||
} | ||
}, | ||
{ | ||
"name": "rewards", | ||
"owner": "masternodes", | ||
"constructor_args": null | ||
}, | ||
{ | ||
"name": "foundation", | ||
"owner": null, | ||
"constructor_args": { | ||
"vk": "13ca9a62d10cbc28d55408e0a85d31f5c059fe3bb49316538e1d03064f3f2c8e" | ||
} | ||
}, | ||
{ | ||
"name": "dao", | ||
"owner": "masternodes", | ||
"constructor_args": null | ||
}, | ||
{ | ||
"name": "members", | ||
"submit_as": "masternodes", | ||
"owner": null, | ||
"constructor_args": { | ||
"genesis_nodes": ["13ca9a62d10cbc28d55408e0a85d31f5c059fe3bb49316538e1d03064f3f2c8e","d37ddb28488fe1bae65279934d6800fae11b26f7c01511b76ca6e602bbc2398d", "40447f46cea1260dd7487833cff630a65b7868f19aafdfd6465b989c9a6dba0e","8e73052eed03e60d4f27e4e422c0742cd2a755ac034122bd504a87afad746f8a","ca9aeee192854dc55a6d3e211bf858cc3ecd41e8b86a55c07740ece29f349597"], | ||
"genesis_registration_fee": 100000 | ||
} | ||
}, | ||
{ | ||
"name": "vault", | ||
"submit_as": "team_lock", | ||
"owner": null, | ||
"constructor_args": { | ||
"initial_owners":"6ebd8090a80e5fc629f38fceefd05d66035a5a4d4ba2c223319ec8f9b83cb48a,081e233f4e122a5fd79ff3c44f9d58848c3214f7110130936661394403100a9a,503ccb3dc04eaaed7c72c3ee6d22368e48a7f7e52b8577f4a4a9989eec51a0be", | ||
"initial_required_signatures": 2, | ||
"stream": "team_vesting" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import currency | ||
|
||
owners = Hash() | ||
required_signatures = Variable() | ||
owner_count = Variable() | ||
transaction_count = Variable() | ||
stream_id = Variable() | ||
transactions = Hash() | ||
|
||
@construct | ||
def seed(initial_owners: str, initial_required_signatures: int, stream: str): | ||
""" | ||
Initializes the multisig contract. | ||
- initial_owners: Comma-separated string of owner addresses. | ||
- initial_required_signatures: Number of required signatures to execute a transaction. | ||
""" | ||
owner_list = initial_owners.split(',') | ||
for owner in owner_list: | ||
owners[owner.strip()] = True | ||
|
||
required_signatures.set(initial_required_signatures) | ||
owner_count.set(len(owner_list)) | ||
transaction_count.set(0) | ||
stream_id.set(stream) | ||
|
||
@export | ||
def submit_transaction(to: str = None, amount: float = None, tx_type: str = 'transfer'): | ||
""" | ||
Submits a new transaction to the multisig wallet. | ||
- to: Recipient address. | ||
- amount: Amount of tokens to transfer. | ||
- tx_type: Type of transaction ('transfer', 'addOwner', 'removeOwner', 'changeRequirement'). | ||
""" | ||
assert owners[ctx.caller], 'Only owners can submit transactions.' | ||
|
||
tx_id = transaction_count.get() + 1 | ||
transaction_count.set(tx_id) | ||
|
||
transactions[tx_id, 'type'] = tx_type | ||
transactions[tx_id, 'to'] = to | ||
transactions[tx_id, 'amount'] = amount | ||
transactions[tx_id, 'executed'] = False | ||
transactions[tx_id, 'approvals'] = 0 | ||
|
||
# The submitter approves the transaction by default | ||
approve_transaction(tx_id) | ||
|
||
return f"Transaction {tx_id} submitted." | ||
|
||
@export | ||
def approve_transaction(tx_id: int): | ||
""" | ||
Approves a pending transaction. | ||
- tx_id: The ID of the transaction to approve. | ||
""" | ||
assert owners[ctx.caller], 'Only owners can approve transactions.' | ||
assert not transactions[tx_id, 'executed'], 'Transaction already executed.' | ||
assert transactions[tx_id, 'type'] is not None, 'Transaction does not exist.' | ||
assert not transactions[tx_id, 'approvers', ctx.caller], 'Already approved.' | ||
|
||
transactions[tx_id, 'approvers', ctx.caller] = True | ||
transactions[tx_id, 'approvals'] += 1 | ||
|
||
return f"Transaction {tx_id} approved by {ctx.caller}." | ||
|
||
@export | ||
def execute_transaction(tx_id: int): | ||
""" | ||
Executes a transaction if enough approvals are collected. | ||
- tx_id: The ID of the transaction to execute. | ||
""" | ||
assert owners[ctx.caller], 'Only owners can execute transactions.' | ||
assert not transactions[tx_id, 'executed'], 'Transaction already executed.' | ||
assert transactions[tx_id, 'type'] is not None, 'Transaction does not exist.' | ||
approvals = transactions[tx_id, 'approvals'] | ||
required = required_signatures.get() | ||
assert approvals >= required, 'Not enough approvals.' | ||
|
||
tx_type = transactions[tx_id, 'type'] | ||
to = transactions[tx_id, 'to'] | ||
amount = transactions[tx_id, 'amount'] | ||
|
||
if tx_type == 'transfer': | ||
currency.transfer(amount=amount, to=to) | ||
elif tx_type == 'addOwner': | ||
assert to is not None, 'No owner specified to add.' | ||
assert not owners[to], 'Address is already an owner.' | ||
owners[to] = True | ||
owner_count.set(owner_count.get() + 1) | ||
elif tx_type == 'removeOwner': | ||
assert to is not None, 'No owner specified to remove.' | ||
assert owners[to], 'Address is not an owner.' | ||
owners[to] = False | ||
owner_count.set(owner_count.get() - 1) | ||
if required_signatures.get() > owner_count.get(): | ||
required_signatures.set(owner_count.get()) | ||
elif tx_type == 'changeRequirement': | ||
assert amount is not None, 'No new requirement specified.' | ||
new_requirement = int(amount) | ||
assert new_requirement > 0, 'Requirement must be greater than zero.' | ||
total_owners = owner_count.get() | ||
assert new_requirement <= total_owners, 'Requirement cannot be greater than number of owners.' | ||
required_signatures.set(new_requirement) | ||
else: | ||
return 'Invalid transaction type.' | ||
|
||
transactions[tx_id, 'executed'] = True | ||
|
||
return f"Transaction {tx_id} executed." | ||
|
||
@export | ||
def balance_stream(): | ||
""" | ||
Executes balance_stream function from currency | ||
contract which sends tokens to this contract | ||
""" | ||
currency.balance_stream(stream_id.get()) |
Oops, something went wrong.