Ejemplo n.º 1
0
def faucetPost(faucetRequest: FaucetRequest, request: Request):
    address = faucetRequest.address
    ip = ipaddress.ip_address(request.client.host)
    if ip.is_private:
        host = request.headers.get('X-Real-IP')
        if host:
            addr = ipaddress.ip_address(host)
        else:
            addr = request.client.host
    else:
        addr = request.client.host
    request_before = request_faucet_TTCache.get(addr)
    if request_before:
        return FaucetResponse(deployID=request_before[1],
                              message='IP:{}, Your request for testnet rev to {} is too high. Try later'.format(
                                  addr, request_before[0]))
    else:
        try:
            with RClient(setting.TARGET_TESTNET_HOST, setting.TARGET_TESTNET_PORT) as client:
                vault = VaultAPI(client)
                private = PrivateKey.from_hex(setting.TESTNET_FAUCET_PRIVATE_KEY)
                deployId = vault.transfer_ensure(private.get_public_key().get_rev_address(), address,
                                                 setting.TESTNET_FAUCET_AMOUNT, private)
                request_faucet_TTCache[addr] = (address, deployId, request.client.host)
                return FaucetResponse(deployID=deployId,
                                      message="Transfer to your address is done. You will receive the rev in some time")
        except RClientException as e:
            return FaucetResponse(deployID='',
                                  message="There is something with server {}. "
                                          "Please contact the maintainer to solve it.".format(e))
Ejemplo n.º 2
0
def faucet(address: str, request: Request):
    request_before = request_faucet_TTCache.get(request.client.host)
    if request_before:
        return FaucetResponse(
            deployID='',
            message='Your request for testnet rev is too high. Try later.')
    else:
        try:
            with RClient(setting.TARGET_TESTNET_HOST,
                         setting.TARGET_TESTNET_PORT) as client:
                vault = VaultAPI(client)
                private = PrivateKey.from_hex(
                    setting.TESTNET_FAUCET_PRIVATE_KEY)
                deployId = vault.transfer(
                    private.get_public_key().get_rev_address(), address,
                    setting.TESTNET_FAUCET_AMOUNT, private)
                request_faucet_TTCache[request.client.host] = address
                return FaucetResponse(
                    deployID=deployId,
                    message=
                    "Transfer to your address is done. You will receive the rev in some time"
                )
        except RClientException as e:
            return FaucetResponse(
                deployID='',
                message="There is something with server {}. "
                "Please contact the maintainer to solve it.".format(e))
Ejemplo n.º 3
0
                    help="private key of the sender vault")
parser.add_argument("-r",
                    "--receiver",
                    action="store",
                    type=str,
                    required=True,
                    dest="receiver",
                    help="receiver of the transfer")
parser.add_argument("-a",
                    "--amount",
                    action="store",
                    type=int,
                    required=True,
                    dest="amount",
                    help="the amount of the transfer")

args = parser.parse_args()
try:
    private_key = PrivateKey.from_hex(args.private_key)
except:
    logging.error("The private you provided is not valid")
    sys.exit(1)

with grpc.insecure_channel('localhost:40401') as channel:
    client = RClient(channel)
    vault = VaultAPI(client, private_key)
    vault.transfer(from_addr=None, to_addr=args.receiver, amount=args.amount)
    logging.info("Succeed transfer {} from {} to {} .".format(
        args.amount,
        private_key.get_public_key().get_rev_address(), args.receiver))
Ejemplo n.º 4
0
# Requires the following line in wallets.txt
#
# 0x06a441c277bf454c5d159b0e5bdafca69b296733,1000000,0

import grpc

from rchain.crypto import PrivateKey
from rchain.client import RClient

from rchain.vault import VaultAPI

alice_key = PrivateKey.from_hex(
    "2a6cd3b196a0b154446a23443cee70629cdb3db0398ea6fb099175708f47f590")
alice_public_key = alice_key.get_public_key()

print("Private key is " + alice_key.to_hex())
print("Public key is " + alice_public_key.to_hex())
print("Eth address is " + alice_public_key.get_eth_address())
print("Rev address is " + alice_public_key.get_rev_address())

with grpc.insecure_channel('localhost:10401') as channel:
    client = RClient(channel)

    alice_vault_api = VaultAPI(client, alice_key)
    alice_vault_api.bond(amount=100)

    alice_bal_deploy_id = alice_vault_api.deploy_get_balance()
    client.propose()

    alice_bal = alice_vault_api.get_balance_from_deploy_id(alice_bal_deploy_id)
    assert alice_bal == 999900
Ejemplo n.º 5
0
    'node5.root-shard.mainnet.rchain.coop',
    'node6.root-shard.mainnet.rchain.coop',
    'node7.root-shard.mainnet.rchain.coop',
    'node8.root-shard.mainnet.rchain.coop'
]
READONLY_SERVER = [
    'observer-asia.services.mainnet.rchain.coop',
    'observer-us.services.mainnet.rchain.coop',
    'observer-eu.services.mainnet.rchain.coop'
]

alice = PrivateKey.from_hex(
    '61e594124ca6af84a5468d98b34a4f3431ef39c54c6cf07fe6fbf8b079ef64f6')
bob = PrivateKey.generate()

exploratory_term = 'new return in{return!("a")}'

with RClient(READONLY_SERVER[0], 40401) as client:
    vault = VaultAPI(client)
    # get the balance of a vault
    # get balance can only perform in the read-only node
    bob_balance = vault.get_balance(bob.get_public_key().get_rev_address())

with RClient(MAINNET_SERVER[0], 40401) as client:
    # because transfer need a valid deploy
    # the transfer need the private to perform signing
    vault = VaultAPI(client)
    deployId = vault.transfer(alice.get_public_key().get_rev_address(),
                              bob.get_public_key().get_rev_address(), 100000,
                              alice)
Ejemplo n.º 6
0
def main():
    god_key = PrivateKey.generate()
    alice_key = PrivateKey.generate()
    bob_key = PrivateKey.generate()

    god_addr = god_key.get_public_key().get_rev_address()
    alice_addr = alice_key.get_public_key().get_rev_address()
    bob_addr = bob_key.get_public_key().get_rev_address()

    with grpc.insecure_channel('172.27.0.2:40401') as channel:
        client = RClient(channel)

        god_vault_api = VaultAPI(client, god_key)
        alice_vault_api = VaultAPI(client, alice_key)
        bob_vault_api = VaultAPI(client, bob_key)

        # Most methods without deploy_ prefix create block (propose) after
        # deploy. To deploy a batch and then create block do:
        #
        #  alice_vault_api.deploy_create_vault()
        #  bob_vault_api.deploy_create_vault()
        #  client.propose()

        alice_vault_api.create_vault()
        bob_vault_api.create_vault()

        assert god_vault_api.get_balance() == 100_000
        assert alice_vault_api.get_balance() == 0
        assert bob_vault_api.get_balance() == 0

        god_vault_api.transfer(None, alice_addr, 1000)

        # Example way to get balances in one block:

        god_bal_deploy_id = god_vault_api.deploy_get_balance()
        alice_bal_deploy_id = alice_vault_api.deploy_get_balance()
        bob_bal_deploy_id = bob_vault_api.deploy_get_balance()
        client.propose()

        god_bal = god_vault_api.get_balance_from_deploy_id(god_bal_deploy_id)
        alice_bal = alice_vault_api.get_balance_from_deploy_id(
            alice_bal_deploy_id)
        bob_bal = bob_vault_api.get_balance_from_deploy_id(bob_bal_deploy_id)

        assert god_bal == 99_000
        assert alice_bal == 1000
        assert bob_bal == 0

        alice_vault_api.transfer(None, bob_addr, 400)

        assert god_vault_api.get_balance() == 99_000
        assert alice_vault_api.get_balance() == 600
        assert bob_vault_api.get_balance() == 400
Ejemplo n.º 7
0
def main():
    god_key = PrivateKey.from_hex(
        "9a801debae8bb97fe54c99389cafa576c60612503348578125b65ab182ff5850")
    alice_key = PrivateKey.from_hex(
        "b2527b00340a83e302beae2a8daf6d654e8e57541acfa261cc1b5635eb16aa15")
    bob_key = PrivateKey.from_hex(
        "567ea426deaeb8233f134c3a266149fb196d6eea7d28b447dfefff92002cb400")

    alice_addr = PrivateKey.from_hex(
        "b2527b00340a83e302beae2a8daf6d654e8e57541acfa261cc1b5635eb16aa15"
    ).get_public_key().get_rev_address()
    god_addr = PrivateKey.from_hex(
        "9a801debae8bb97fe54c99389cafa576c60612503348578125b65ab182ff5850"
    ).get_public_key().get_rev_address()
    bob_addr = PrivateKey.from_hex(
        "567ea426deaeb8233f134c3a266149fb196d6eea7d28b447dfefff92002cb400"
    ).get_public_key().get_rev_address()

    with grpc.insecure_channel('rchain-kuxgz.bootstrap:40401') as channel:
        client = RClient(channel)

        god_vault_api = VaultAPI(client, god_key)
        alice_vault_api = VaultAPI(client, alice_key)
        bob_vault_api = VaultAPI(client, bob_key)

        # Most methods without deploy_ prefix create block (propose) after
        # deploy. To deploy a batch and then create block do:
        #
        #  alice_vault_api.deploy_create_vault()
        #  bob_vault_api.deploy_create_vault()
        #  client.propose()

        alice_vault_api.create_vault()
        bob_vault_api.create_vault()

        assert alice_vault_api.get_balance() == 5000
        assert god_vault_api.get_balance() == 0
        assert bob_vault_api.get_balance() == 0

        alice_vault_api.transfer(None, bob_addr, 1000)

        # Example way to get balances in one block:

        god_bal_deploy_id = god_vault_api.deploy_get_balance()
        alice_bal_deploy_id = alice_vault_api.deploy_get_balance()
        bob_bal_deploy_id = bob_vault_api.deploy_get_balance()
        client.propose()

        god_bal = god_vault_api.get_balance_from_deploy_id(god_bal_deploy_id)
        alice_bal = alice_vault_api.get_balance_from_deploy_id(
            alice_bal_deploy_id)
        bob_bal = bob_vault_api.get_balance_from_deploy_id(bob_bal_deploy_id)

        assert god_bal == 0
        assert alice_bal == 4000
        assert bob_bal == 1000

        bob_vault_api.transfer(None, god_addr, 400)

        assert god_vault_api.get_balance() == 400
        assert alice_vault_api.get_balance() == 4000
        assert bob_vault_api.get_balance() == 600