Пример #1
0
def solo_connector():
    endpoints = ["http://localhost:8669", "http://solo.veblocks.net"]
    for x in endpoints:
        c = Connect(x)
        try:
            c.get_chainTag()
            return c
        except:
            continue

    raise Exception("Cannot connect to a reliable solo node to run tests")
Пример #2
0
def helper_transact(connector: Connect,
                    wallet: Wallet,
                    contract_addr: str,
                    contract: Contract,
                    func_name: str,
                    func_params: list,
                    value: int = 0):
    '''Transact on-chain, and return reverted(bool), receipt'''
    res = connector.transact(wallet,
                             contract,
                             func_name,
                             func_params,
                             contract_addr,
                             value=value,
                             force=True)
    assert res["id"]
    receipt = connector.wait_for_tx_receipt(res["id"])
    return receipt["reverted"], receipt
Пример #3
0
def helper_call(connector: Connect,
                caller: str,
                contract_addr: str,
                contract: Contract,
                func_name: str,
                func_params: list,
                value: int = 0):
    '''Call on-chain, return reverted(bool), response'''
    # Call to get the balance of user's vtho
    res = connector.call(caller,
                         contract,
                         func_name,
                         func_params,
                         contract_addr,
                         value=value)
    return res["reverted"], res
Пример #4
0
def helper_wait_for_block(connector: Connect, number: int = 1):
    counter = 0
    for block in connector.ticker():
        counter += 1
        if counter >= number:
            break
NETWORK = sys.argv[1]  # eg. 'https://solo.veblocks.net'
PRIVATE_KEY = sys.argv[2]
FACTORY_FILE = sys.argv[3]
FACTORY_ADDRESS = sys.argv[4]
token_1_address = sys.argv[5]
token_2_address = sys.argv[6]

if not token_1_address:
    raise Exception("fill out the token 1 smart contract address")

if not token_2_address:
    raise Exception("fill out the token 2 smart contract address")

# Prepare wallet and network
w = Wallet.fromPrivateKey(bytes.fromhex(PRIVATE_KEY))
c = Connect(NETWORK)
factory_contract = Contract.fromFile(FACTORY_FILE)

if not utils.is_contract(c.get_account(FACTORY_ADDRESS)):
    raise Exception(f"{FACTORY_ADDRESS} is not a smart contract")

if not utils.is_contract(c.get_account(token_1_address)):
    raise Exception(f"{token_1_address} is not a smart contract")

if not utils.is_contract(c.get_account(token_2_address)):
    raise Exception(f"{token_2_address} is not a smart contract")

# Call on factory to create a pool of token 1 and token 2
response = c.transact(w, factory_contract, 'createPair',
                      [token_1_address, token_2_address], FACTORY_ADDRESS)
tx_id = response['id']
Пример #6
0
from thor_requests import utils

# Global params
TOP = 220
SLEEP = 11

# Read in Params
SCRIPT_NAME = sys.argv[0]
NETWORK = sys.argv[1]  # eg. 'https://solo.veblocks.net'
PRIVATE_KEY = sys.argv[2]
COMTRACT_FILE = sys.argv[3]
CONTRACT_ADDRESS = sys.argv[4]

# Prepare wallet and network
w = Wallet.fromPrivateKey(bytes.fromhex(PRIVATE_KEY))
c = Connect(NETWORK)
smart_contract = Contract.fromFile(COMTRACT_FILE)

# Detect wallet balance
account = c.get_account(w.getAddress())
print('Wallet:')
print('VET:', int(account['balance'], 16) / (10**18))
print('VTHO:', int(account['energy'], 16) / (10**18))
print('Is human:', not utils.is_contract(account))

# Emulate the call of getting a random number
if not utils.is_contract(c.get_account(CONTRACT_ADDRESS)):
    raise Exception(f"{CONTRACT_ADDRESS} is not a smart contract")

# best block
# block = c.get_block()
Пример #7
0
# Usually costs 691 VTHO.
# Inputs: network url, json file, deployer wallet
import sys
from thor_requests.connect import Connect
from thor_requests.wallet import Wallet
from thor_requests.contract import Contract
from thor_requests import utils
# Read in Params
SCRIPT_NAME = sys.argv[0]
NETWORK = sys.argv[1]  # eg. 'https://solo.veblocks.net'
PRIVATE_KEY = sys.argv[2]
VVET_FILE = sys.argv[3]

# Prepare wallet and network
w = Wallet.fromPrivateKey(bytes.fromhex(PRIVATE_KEY))
c = Connect(NETWORK)
vvet_contract = Contract.fromFile(VVET_FILE)

# Detect wallet balance
account = c.get_account(w.getAddress())
print('Wallet:')
print('VET:', int(account['balance'], 16) / (10**18))
print('VTHO:', int(account['energy'], 16) / (10**18))
print('Is human:', not utils.is_contract(account))

# Deploy
response = c.deploy(w, vvet_contract, None, None)
tx_id = response['id']
print('deploy_vvet_tx:', tx_id)

# Wait for Receipt
from thor_requests.connect import Connect
from thor_requests.wallet import Wallet
from thor_requests.contract import Contract
from thor_requests import utils

# Read in Params
SCRIPT_NAME = sys.argv[0]
NETWORK = sys.argv[1]  # eg. 'https://solo.veblocks.net'
PRIVATE_KEY = sys.argv[2]
FACTORY_FILE = sys.argv[3]
ROUTER_FILE = sys.argv[4]
VVET_CONTRACT_ADDRESS = sys.argv[5]

# Prepare wallet and network
w = Wallet.fromPrivateKey(bytes.fromhex(PRIVATE_KEY))
c = Connect(NETWORK)
factory_contract = Contract.fromFile(FACTORY_FILE)
router_contract = Contract.fromFile(ROUTER_FILE)
vvet_contract_address = VVET_CONTRACT_ADDRESS
if not vvet_contract_address:
    raise Exception("Set vVET contract address first!")

# Detect if VVET contract is ready
a = c.get_account(vvet_contract_address)
if not utils.is_contract(a):
    raise Exception(f"{vvet_contract_address} is not a smart contract")

# Detect wallet balance
account = c.get_account(w.getAddress())
print('Wallet balance:')
print('VET:', int(account['balance'], 16) / (10**18))
from thor_requests.wallet import Wallet
from thor_requests.connect import Connect
from thor_requests.contract import Contract

# Set up a connection to VeChain blockchain
connector = Connect("http://localhost:8669")

# VTHO token contract address
vtho_contract_address = "0x0000000000000000000000000000456e65726779"

# Set up the VTHO contract object
vtho_contract = Contract.fromFile("./VTHO.json")

# Set up the sender's wallet
sender = Wallet.fromMnemonic([
    "denial",
    "kitchen",
    "pet",
    "squirrel",
    "other",
    "broom",
    "bar",
    "gas",
    "better",
    "priority",
    "spoil",
    "cross",
])

# Set up the receiver's wallet (a brand new wallet)
receiver = Wallet.newWallet()
Пример #10
0
# Inputs: network url, json file, deployer wallet
import sys
from thor_requests.connect import Connect
from thor_requests.wallet import Wallet
from thor_requests.contract import Contract
from thor_requests import utils
# Read in Params
SCRIPT_NAME = sys.argv[0]
NETWORK = sys.argv[1] # eg. 'https://solo.veblocks.net'
PRIVATE_KEY = sys.argv[2]
COMTRACT_FILE = sys.argv[3]
HOW_MANY_BLOCKS_LATER = sys.argv[4]

# Prepare wallet and network
w = Wallet.fromPrivateKey(bytes.fromhex(PRIVATE_KEY))
c = Connect(NETWORK)
smart_contract = Contract.fromFile(COMTRACT_FILE)

# Detect wallet balance
account = c.get_account(w.getAddress())
print('Wallet:')
print('VET:', int(account['balance'], 16) / (10 ** 18))
print('VTHO:', int(account['energy'], 16) / (10 ** 18))
print('Is human:', not utils.is_contract(account))

# Deploy
## get block
block = c.get_block()
best_block_number = int(block['number'])
stop_block_number = best_block_number + int(HOW_MANY_BLOCKS_LATER)
response = c.deploy(w, smart_contract, ['uint', 'bool', 'uint'], [stop_block_number, True, 1 * (10**18)])
Пример #11
0
from thor_requests import utils

# Global params
TOP = 20000
SLEEP = 11

# Read in Params
SCRIPT_NAME = sys.argv[0]
NETWORK = sys.argv[1]  # eg. 'https://solo.veblocks.net'
PRIVATE_KEY = sys.argv[2]
COMTRACT_FILE = sys.argv[3]
CONTRACT_ADDRESS = sys.argv[4]

# Prepare wallet and network
w = Wallet.fromPrivateKey(bytes.fromhex(PRIVATE_KEY))
c = Connect(NETWORK)
smart_contract = Contract.fromFile(COMTRACT_FILE)

# Detect wallet balance
account = c.get_account(w.getAddress())
print('Wallet:')
print('VET:', int(account['balance'], 16) / (10**18))
print('VTHO:', int(account['energy'], 16) / (10**18))
print('Is human:', not utils.is_contract(account))

if not utils.is_contract(c.get_account(CONTRACT_ADDRESS)):
    raise Exception(f"{CONTRACT_ADDRESS} is not a smart contract")

# Emulate call of current block number/stop block number
block = c.get_block()
best_block_number = int(block['number'])
ROUTER02_ADDRESS = sys.argv[4]
token_1_address = sys.argv[5]
token_2_address = sys.argv[6]
ERC20_FILE = sys.argv[7]
token_1_amount = int(sys.argv[8])
token_2_amount = int(sys.argv[9])

if not token_1_address:
    raise Exception("fill out the token 1 smart contract address")

if not token_2_address:
    raise Exception("fill out the token 2 smart contract address")

# Prepare wallet, network, contract
w = Wallet.fromPrivateKey(bytes.fromhex(PRIVATE_KEY))
c = Connect(NETWORK)
router02_contract = Contract.fromFile(ROUTER02_FILE)
erc20_contract = Contract.fromFile(ERC20_FILE)

if not utils.is_contract(c.get_account(ROUTER02_ADDRESS)):
    raise Exception(f"{ROUTER02_ADDRESS} is not a smart contract")

if not utils.is_contract(c.get_account(token_1_address)):
    raise Exception(f"{token_1_address} is not a smart contract")

if not utils.is_contract(c.get_account(token_2_address)):
    raise Exception(f"{token_2_address} is not a smart contract")

# Call to approve() vtho to be used by router02
response = c.transact(w, erc20_contract, 'approve',
                      [ROUTER02_ADDRESS, token_2_amount], token_2_address)
Пример #13
0
def mainnet_connector():
    return Connect("http://mainnet.veblocks.net")
Пример #14
0
def testnet_connector():
    return Connect("http://testnet.veblocks.net")