Пример #1
0
 def __init__(self):
     self.web3 = Web3Interface().w3
     parser = argparse.ArgumentParser()
     parser.add_argument("-n",
                         "--network",
                         default="poanet",
                         help="Enter network, defaults to poanet")
     parser.add_argument("-p",
                         "--provider",
                         default="http",
                         help="Enter provider, defaults to http")
     parser.add_argument("-a",
                         "--address",
                         help="Enter address to look for log file")
     parser.add_argument("-d",
                         "--deployment_name",
                         help="Enter deployment name to look for log file")
     parser.add_argument("-t",
                         "--test",
                         action="store_true",
                         help="Testing mode")
     parser.add_argument("-c", "--configurate", action="store_true")
     self.args = parser.parse_args()
Пример #2
0
 def __init__(self):
     self.web3 = Web3Interface().w3
parser = argparse.ArgumentParser()
parser.add_argument("-n",
                    "--network",
                    default="poanet",
                    help="Enter network, defaults to poanet")
parser.add_argument("-p",
                    "--provider",
                    default="http",
                    help="Enter provider, defaults to http")
parser.add_argument("-t", "--test", action="store_true", help="Testing mode")
parser.add_argument("-c", "--configurate", action="store_true")
args = parser.parse_args()

# web3.py instance
web3 = Web3Interface().w3
miner = web3.miner
if web3.net.version == "1":
    sender_account = "0x54d9249C776C56520A62faeCB87A00E105E8c9Dc"
else:
    sender_account = web3.eth.accounts[0]
gas = 4500000
log_path = "./log/"
compiled_path = "./build/"
tx_hash = None

if args.test:
    unlocker.unlock()
    miner.start(1)
    contract_name = "Crowdsale"
    gas_price = 5000000000
Пример #4
0
def unlock():
  web3 = Web3Interface().w3
  for x in web3.eth.accounts:
    web3.personal.unlockAccount(x, 'cuentahoracio0', 10000)
Пример #5
0
class Token:

  gas = 50000000
  gas_price = 20000000000
  params = None
  
  web3 = Web3Interface(middleware=True).w3
  miner = web3.miner
  accounts = web3.eth.accounts
  sender_account = accounts[0]
  owner = None

  def __init__(self, crowdsale_contract):
    self.owner = crowdsale_contract.address
    # Get CrowdsaleToken ABI
    with open("./build/CrowdsaleToken.abi") as token_abi_file:
      token_abi = json.load(token_abi_file)
    
    token_address = crowdsale_contract.functions.token().call()
    self.contract = self.web3.eth.contract(address=token_address, abi=token_abi)
  
  # Custom functions-------------------------------------------------------------------------
  def balances(self):
    for i in self.web3.eth.accounts:
      print(balance_of(i))

  def get_transaction_receipt(self, tx_hash):
    self.wait(tx_hash)
    return self.web3.eth.getTransactionReceipt(tx_hash)

  # Transaction parameter
  def transaction_info(self, sender, value=0):
    return {"from": sender, "value": value*(10**18), "gas": self.gas, "gasPrice": self.gas_price}

  def wait(self, tx_hash):
    while self.web3.eth.getTransactionReceipt(tx_hash) == None:
      time.sleep(1)

  # Token Contract's functions---------------------------------------------------------------
  def add_approval(self, spender, addedValue):
    return self.contract.functions.addApproval(spender, addedValue).transact(self.transaction_info(self.sender_account))
  
  def allowance(self, account, spender):
    return self.contract.functions.allowance(account, spender).call()
  
  def approve(self, spender, value):
    return self.contract.functions.approve(spender, value).transact(self.transaction_info(self.sender_account))
  
  def balance_of(self, investor):
    if isinstance(investor, str):
      return self.contract.functions.balanceOf(investor).call()
    else:
      return self.contract.functions.balanceOf(self.web3.eth.accounts[investor]).call()
  
  def can_upgrade(self):
    return self.contract.functions.canUpgrade().call()
  
  def change_upgrade_master(self, newMaster):
    return self.contract.functions.changeUpgradeMaster(newMaster).transact(self.transaction_info(self.sender_account))
  
  def decimals(self):
    return self.contract.functions.decimals().call()
  
  def enable_lost_and_found(self, agent, tokens, token_contr):
    return self.contract.functions.enableLostAndFound(agent, tokens, token_contr).transact(self.transaction_info(self.sender_account))
  
  def get_upgrade_state(self):
    return self.contract.functions.getUpgradeState().call()
  
  def set_transfer_agent(self, addr, state):
    return self.get_transaction_receipt(self.contract.functions.setTransferAgent(addr, state).transact(self.transaction_info(self.owner)))

  def sub_approval(self, spender, subtractedValue):
    return self.contract.functions.subApproval(spender, subtractedValue).transact(self.transaction_info(self.sender_account))
  
  def total_supply(self):
    return self.contract.functions.totalSupply().call()
  
  def transfer_agents(self, agent):
    return self.contract.functions.transferAgents(agent).call()

  def transfer(self, to, value):
    return self.contract.functions.transfer(to, value).transact(self.transaction_info(self.sender_account))
  
  def transferFrom(self, from_addr, to, value):
    return self.contract.functions.transferFrom(from_addr, to, value).transact(self.transaction_info(self.sender_account))
class Crowdsale:
  parser = argparse.ArgumentParser()
  parser.add_argument("-n", "--network", default="poanet")
  parser.add_argument("-p", "--provider", default="http")
  parser.add_argument("-t", "--test", action="store_true")
  args = parser.parse_args()

  gas = 5000000
  gas_price = 20000000000
  params = None
    
  # web3.py instance
  web3 = Web3Interface().w3
  miner = web3.miner
  accounts = web3.eth.accounts
  if args.network == "mainnet":
    sender_account = "0x54d9249C776C56520A62faeCB87A00E105E8c9Dc"
  else:
    sender_account = web3.eth.accounts[0]
  contract = None
  tokens_to_preallocate = 10
  wei_price_of_preallocation = 350
  states = {"Unknown": 0, "PendingConfiguration": 1, "PreFunding": 2, "Funding": 3, "Success": 4, "Finalized": 5}
  
  def __init__(self, config_params):
    self.params = config_params
    loader = ContractLoader()
    self.contract = loader.load("./build/", "Crowdsale", address_path="./address_log/")

  # Custom functions-------------------------------------------------------------------------
  def get_transaction_receipt(self, tx_hash):
    self.wait(tx_hash)
    return self.web3.eth.getTransactionReceipt(tx_hash)

  # Transaction parameter
  def transaction_info(self, sender, value=0):
    return {"from": sender, "value": value*(10**18), "gas": self.gas, "gasPrice": self.gas_price}

  def wait(self, tx_hash):
    while self.web3.eth.getTransactionReceipt(tx_hash) == None:
      time.sleep(1)

  def send_ether_to_crowdsale(self, buyer, value):
    return self.get_transaction_receipt(self.web3.eth.sendTransaction({'from': buyer, 'to': self.contract.address, 'value': value * (10 ** 18), 'gas': 100000000}))

  def eta_ico(self):
    return round(self.starts_at()-time.time())

  def eta_end_ico(self):
    return round(self.ends_at()-time.time())

  def start_ico(self):
    print("ETA for ICO: " + str(self.eta_ico() + 1) + " seconds.")
    time.sleep(max(0, self.eta_ico() + 1))
    print("ICO STARTS")

  def end_ico(self):
    tokens_sold = self.tokens_sold()
    sellable_tokens = self.sellable_tokens()
    if tokens_sold >= sellable_tokens:
      print("ICO ENDS")
    else:
      print("ETA for ICO's end: " + str(self.eta_end_ico() + 1) + " seconds.")
      time.sleep(max(0, self.eta_end_ico() + 1))
      print("ICO ENDS")


  # Crowdsale Contract's functions-----------------------------------------------------------
  def buy(self, buyer, value):
    return self.get_transaction_receipt(self.contract.functions.buy().transact(self.transaction_info(buyer, value)))

  def buy_on_behalf(self, buyer, receiver, value):
    return self.get_transaction_receipt(self.contract.functions.buyOnBehalf(receiver).transact(self.transaction_info(buyer, value)))
  
  def buy_on_behalf_with_customer_id(self, buyer, receiver, customerId, value):
    return self.get_transaction_receipt(self.contract.functions.buyOnBehalfWithCustomerId(receiver, customerId).transact(self.transaction_info(buyer, value)))
  
  def buy_on_behalf_with_signed_address(self, buyer, receiver, customerId, v, r, s, value):
    return self.get_transaction_receipt(self.contract.functions.buyOnBehalfWithSignedAddress(receiver, customerId, v, r, s).transact(self.transaction_info(buyer, value)))
  
  def buy_with_customer_id(self, customerId, buyer, value):
    return self.get_transaction_receipt(self.contract.functions.buyWithCustomerId(customerId).transact(self.transaction_info(buyer, value)))
  
  def buy_with_signed_address(self, customerId, v, r, s, buyer, value):
    return self.get_transaction_receipt(self.contract.functions.buyWithSignedAddress(customerId, v, r, s).transact(self.transaction_info(buyer, value)))
  
  def configuration_crowdsale(self):
    param_list = [self.params['MW_address'], self.params['startTime'], self.params['endTime'], self.params['token_retriever_account'], self.params['tranches'], self.params['multisig_supply'], self.params['crowdsale_supply'], self.params['token_decimals'], self.params['max_tokens_to_sell']]
    return self.get_transaction_receipt(self.contract.functions.configurationCrowdsale(*param_list).transact({"from": self.sender_account, "value": 0, "gas": self.gas, "gasPrice": self.gas_price}))

  def configured(self):
    return self.contract.functions.configured().call()
  
  def early_participant_whitelist(self, address):
    return self.contract.functions.earlyParticipantWhitelist(address).call()
  
  def ends_at(self):
    return self.contract.functions.endsAt().call()
  
  def finalize(self):
    return self.get_transaction_receipt(self.contract.functions.finalize().transact(self.transaction_info(self.sender_account)))
  
  def finalized(self):
    return self.contract.functions.finalized().call()
  
  def get_current_price(self):
    return self.contract.functions.getCurrentPrice(self.tokens_sold()).call()

  def get_deployment_block(self):
    return self.contract.functions.getDeploymentBlock().call()
  
  def get_state(self):
    return self.contract.functions.getState().call()
  
  def get_tranches_length(self):
    return self.contract.functions.getTranchesLength().call()
  
  def halt(self):
    return self.get_transaction_receipt(self.contract.functions.halt().transact(self.transaction_info(self.sender_account)))
  
  def halted(self):
    return self.contract.functions.halted().call()
  
  def initial_bounties_tokens(self):
    return self.contract.functions.initial_tokens().call()

  def invested_amount_of(self):
    return self.contract.functions.investedAmountOf().call()
  
  def investor_count(self):
    return self.contract.functions.investorCount().call()
  
  def milieurs_per_eth(self):
    return self.contract.functions.milieurs_per_eth().call()

  def multisig_wallet(self):
    return self.contract.functions.multisigWallet().call()
  
  def minimum_buy_value(self):
    return self.contract.functions.minimum_buy_value().call()

  def owner(self):
    return self.contract.functions.owner().call()
  
  def preallocate(self, receiver, fullTokens, weiPrice):
    return self.get_transaction_receipt(self.contract.functions.preallocate(receiver, fullTokens, weiPrice).transact(self.transaction_info(self.sender_account)))
  
  def require_customer_id(self):
    return self.contract.functions.requireCustomerId().call()
  
  def required_signed_address(self):
    return self.contract.functions.requiredSignedAddress().call()
  
  def sellable_tokens(self):
    return self.contract.functions.sellable_tokens().call()

  def set_early_participant_whitelist(self, addr, status):
    return self.get_transaction_receipt(self.contract.functions.setEarlyParticipantWhitelist(addr, status).transact(self.transaction_info(self.sender_account)))
  
  def set_ending_time(self, endingTime):
    return self.get_transaction_receipt(self.contract.functions.setEndingTime(endingTime).transact(self.transaction_info(self.sender_account)))

  def set_minimum_buy_value(self, new_minimum):
    return self.get_transaction_receipt(self.contract.functions.setMinimumBuyValue(new_minimum).transact(self.transaction_info(self.sender_account)))

  def set_require_customer_id(self, value):
    return self.get_transaction_receipt(self.contract.functions.setRequireCustomerId(value).transact(self.transaction_info(self.sender_account)))
  
  def set_require_signed_address(self, value, signer):
    return self.get_transaction_receipt(self.contract.functions.setRequireSignedAddress(value, signer).transact(self.transaction_info(self.sender_account)))
  
  def set_starting_time(self, startingTime):
    return self.get_transaction_receipt(self.contract.functions.setStartingTime(startingTime).transact(self.transaction_info(self.sender_account)))

  def signer_address(self):
    return self.contract.functions.signerAddress().call()
  
  def starts_at(self):
    return self.contract.functions.startsAt().call()
  
  def token(self):
    return self.contract.functions.token().call()
  
  def token_amount_of(self):
    return self.contract.functions.tokenAmountOf().call()
  
  def tokens_sold(self):
    return self.contract.functions.tokensSold().call()
  
  def tranches(self):
    return self.contract.functions.tranches().call()
  
  def transfer_ownership(self, newOwner):
    return self.get_transaction_receipt(self.contract.functions.transferOwnership(newOwner).transact(self.transaction_info(self.sender_account)))
  
  def unhalt(self):
    return self.get_transaction_receipt(self.contract.functions.unhalt().transact(self.transaction_info(self.sender_account)))

  def update_eurs_per_eth(self, milieurs_amount):
    return self.get_transaction_receipt(self.contract.functions.updateEursPerEth(milieurs_amount).transact(self.transaction_info(self.sender_account)))
  
  def update_price_agent(self, new_price_agent):
    return self.get_transaction_receipt(self.contract.functions.updatePriceAgent(new_price_agent).transact(self.transaction_info(self.sender_account)))

  def wei_raised(self):
    return self.contract.functions.weiRaised().call()
Пример #7
0
 def __init__(self):
   self.web3 = Web3Interface().w3
   self.args, unknown = parse_args(sys.argv[1:])
   self.contract = None