forked from TokenMarketNet/sto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding database managed transaction broadcast
- Loading branch information
Showing
14 changed files
with
667 additions
and
58 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 |
---|---|---|
|
@@ -77,3 +77,5 @@ registrar.json | |
|
||
# Created by pytest | ||
.pytest_cache | ||
|
||
*.sqlite |
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,26 @@ | ||
import os | ||
|
||
from sqlalchemy import create_engine | ||
from sqlalchemy.orm import sessionmaker | ||
|
||
from .models.implementation import Base | ||
|
||
|
||
def setup_database(db_filename): | ||
|
||
# https://docs.sqlalchemy.org/en/latest/dialects/sqlite.html | ||
url = "sqlite+pysqlite:///" + db_filename | ||
|
||
engine = create_engine(url, echo=False) | ||
|
||
if not os.path.exists(url): | ||
init_db(engine) | ||
|
||
Session = sessionmaker(bind=engine) | ||
session = Session() | ||
return session | ||
|
||
|
||
def init_db(engine): | ||
Base.metadata.create_all(engine) | ||
|
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,66 @@ | ||
"""Issuing out tokenised shares.""" | ||
from logging import Logger | ||
|
||
from corporategovernance.ethereum.manifest import get_package | ||
from corporategovernance.ethereum.txservice import EthereumStoredTXService | ||
from corporategovernance.ethereum.utils import get_abi, check_good_private_key | ||
from corporategovernance.models.implementation import BroadcastAccount, PreparedTransaction | ||
from sqlalchemy.orm import Session | ||
from web3 import Web3, HTTPProvider | ||
from web3.contract import Contract | ||
|
||
|
||
def deploy_token_contracts(logger: Logger, | ||
dbsession: Session, | ||
network: str, | ||
ethereum_node_url: str, | ||
ethereum_abi_file: str, | ||
ethereum_private_key: str, | ||
ethereum_gas_limit: str, | ||
ethereum_gas_price: str, | ||
name: str, | ||
symbol: str, | ||
amount: int, | ||
transfer_restriction: str): | ||
"""Issue out a new Ethereum token.""" | ||
|
||
check_good_private_key(ethereum_private_key) | ||
|
||
abi = get_abi(ethereum_abi_file) | ||
|
||
web3 = Web3(HTTPProvider(ethereum_node_url)) | ||
|
||
# We do not have anything else implemented yet | ||
assert transfer_restriction == "unrestricted" | ||
|
||
service = EthereumStoredTXService(network, dbsession, web3, ethereum_private_key, ethereum_gas_price, ethereum_gas_limit, BroadcastAccount, PreparedTransaction) | ||
|
||
# Deploy security token | ||
note = "Token contract for {}".format(name) | ||
deploy_tx1 = service.deploy_contract("SecurityToken", abi, note, constructor_args={"_name": name, "_symbol": symbol}) # See SecurityToken.sol | ||
|
||
# Deploy transfer agent | ||
note = "Unrestricted transfer manager for {}".format(name) | ||
deploy_tx1 = service.deploy_contract("UnrestrictedTransferAgent", abi, note) | ||
|
||
# Set transfer agent | ||
note = "Setting security token transfer manager for {}".format(name) | ||
contract_address = deploy_tx1.contract_address | ||
update_tx1 = service.interact_with_contract("SecurityToken", abi, contract_address, note, "setTransactionVerifier", {"newVerifier": deploy_tx1.contract_address}) | ||
|
||
# Issue out initial shares | ||
note = "Creating {} initial shares for {}".format(amount, name) | ||
contract_address = deploy_tx1.contract_address | ||
amount_18 = amount * 10**18 | ||
update_tx2 = service.interact_with_contract("SecurityToken", abi, contract_address, note, "issueTokens", {"value": amount_18}) | ||
|
||
logger.info("Prepared transactions for broadcasting") | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.