예제 #1
0
def deploy(chain_name, owner, view_authority_addr, view_token_addr):
    """ Deploy ViewTokenMintage """
    with Project().get_chain(chain_name) as chain:
        view_token = load_contract(chain, 'DSToken', view_token_addr)
        view_authority = load_contract(chain, 'DSGuard', view_authority_addr)
        deps = {
            'ViewAuthority': view_authority,
            'ViewToken': view_token,
        }
        deployer = TokenMintage(chain_name, chain, owner=owner, **deps)
        print(f'Head block is {deployer.web3.eth.blockNumber} '
              f'on the "{chain_name}" chain')
        print('Owner address is', deployer.owner)
        print('ViewAuthority address is', view_authority.address)
        print('ViewToken address is', view_token.address)

        if confirm_deployment(chain_name, deployer.__target__):
            deployer.deploy()
            deployer.dump_abis()
예제 #2
0
def init_contract(w3):
    """
    initialise contract object from address, stored in disk file by deploy.py
    """
    contract_address, abi, _ = load_contract(
        file_abi=FILE_CONTRACT_ABI,
        file_bin=FILE_CONTRACT_BIN,
        file_address=FILE_CONTRACT_ADDRESS)
    contract = w3.eth.contract(address=contract_address, abi=abi)
    return contract
예제 #3
0
def deploy(account, timeout=TIMEOUT_DEPLOY):
    """
    deploys contract, waits for receipt, returns address
    """
    before = time.time()
    _, abi, contract_bin = load_contract(file_abi=FILE_CONTRACT_ABI,
                                         file_bin=FILE_CONTRACT_BIN)
    storage_contract = w3.eth.contract(abi=abi, bytecode=contract_bin)
    contract_tx = storage_contract.constructor().buildTransaction({
        'gas':
        GAS_DEPLOY,
        'gasPrice':
        GAS_PRICE,
        'nonce':
        account["nonce"].increment(),
        'chainId':
        CHAIN_ID
    })
    signed = w3.eth.account.signTransaction(contract_tx,
                                            account["private_key"])
    tx_hash = w3.toHex(w3.eth.sendRawTransaction(signed.rawTransaction))

    print("tx_hash = ", tx_hash,
          "--> waiting for receipt (timeout=%d) ..." % timeout)
    sys.stdout.flush()
    # Wait for the transaction to be mined, and get the transaction receipt
    receipt = w3.eth.waitForTransactionReceipt(tx_hash, timeout=timeout)
    print("Receipt arrived. Took %.1f seconds." % (time.time() - before))

    if receipt.status == 1:
        line = "Deployed. Gas Used: {gasUsed}. Contract Address: {contractAddress}"
        print(line.format(**receipt))
        save_address(receipt.contractAddress)
        return
    else:
        line = "Deployed failed. Receipt Status: {status}"
        print(line.format(**receipt))
        exit()
예제 #4
0
#!/usr/bin/env python3
# coding=utf-8

from binascii import hexlify
from io import BytesIO
from flask import Flask, abort, jsonify, render_template, send_file
from hashlib import sha256
from markupsafe import Markup
import re
from web3.auto.infura import w3

from cron import cron
import imagegen
from utils import get_amulet_data, load_contract, RARITIES, tr_whitespace

contract = load_contract(w3, 'Amulet')
visible_whitespace = str.maketrans(' \n\t', '·⏎⇥')

app = Flask(__name__)
app.add_url_rule('/cron', 'cron', cron)


@app.template_filter()
def mdescape(s):
    return Markup(re.sub("([]*_#=`~<>+.()\\&_[-])", r"\\\1", s))


@app.route('/token/<string:tokenhash>.json')
def metadata(tokenhash):
    tokenid = int(tokenhash, 16)
    if tokenid > (1 << 256) - 1:
예제 #5
0
# coding=utf-8

from binascii import hexlify
from io import BytesIO
from flask import Flask, abort, jsonify, render_template, send_file
from hashlib import sha256
from markupsafe import Markup
import re
from web3.auto.infura import w3

from cron import cron
import imagegen
from utils import get_amulet_data, load_contract, RARITIES


contract = load_contract('Amulet')
visible_whitespace = str.maketrans(' \n\t', '·⏎⇥')

app = Flask(__name__)
app.add_url_rule('/cron', 'cron', cron)


@app.template_filter()
def mdescape(s):
    return Markup(re.sub("([]*_#=`~<>+.()\\&_[-])", r"\\\1", s))


@app.route('/token/<string:tokenhash>.json')
def metadata(tokenhash):
    tokenid = int(tokenhash, 16)
    if tokenid > (1 << 256) - 1: