Skip to content
This repository has been archived by the owner on Mar 12, 2022. It is now read-only.

Integration guide #20

Open
guilhermelawless opened this issue Jul 1, 2019 · 1 comment
Open

Integration guide #20

guilhermelawless opened this issue Jul 1, 2019 · 1 comment
Assignees
Labels
documentation Documentation

Comments

@guilhermelawless
Copy link
Owner

guilhermelawless commented Jul 1, 2019

Rough start:

If using internal management, suggest using Betsy and nothing else is necessary. If a pure integration is desired, then increasing the minimum receive is required.

  1. RPC account_info -> grab the frontier (which will be the previous block to your send)
  2. Ask DPoW for work using that hash (the frontier)
  3. RPC Send with the given work

Alternative (advanced):

  1. (Same)
  2. RPC block_create
  3. Work from DPoW
  4. RPC process

For both cases there is an exception - if the account is not created yet, there will be no frontier. In this case the public key should be used, which can be grabbed from RPC account_key.

Finally, keep an eye on the CPU usage during your sends and receives to make sure there is no PoW being re-generated. This would not happen with the advanced method.

@guilhermelawless guilhermelawless added the documentation Documentation label Jul 1, 2019
@guilhermelawless guilhermelawless self-assigned this Jul 1, 2019
@guilhermelawless
Copy link
Owner Author

Python integration example by @mitche50 (can be improved)

def get_pow(sender_account):
    """
    Retrieves the frontier (hash of previous transaction) of the provided account and generates work for the next block.
    """
    try:
        account_info_call = {'action': 'account_info', 'account': sender_account}
        json_request = json.dumps(account_info_call)
        r = requests.post('{}'.format(NODE_IP), data=json_request)
        rx = r.json()
        if 'frontier' in rx.keys():
            hash = rx['frontier']
        else:
            public_key_data = {'action': 'account_key', 'account': sender_account}
            json_request = json.dumps(public_key_data)
            r = requests.post('{}'.format(NODE_IP), data=json_request)
            rx = r.json()
            hash = rx['key']

        logging.info("{}: hash retrieved from account info: {}".format(datetime.now(), hash))
    except Exception as e:
        logging.info("{}: Error checking frontier: {}".format(datetime.now(), e))
        return ''

    work = ''
    try:
        work_data = {'hash': hash, 'api_key': WORK_KEY, 'account': sender_account, 'user': WORK_USER}
        json_request = json.dumps(work_data)
        r = requests.post('{}'.format(WORK_SERVER), data=json_request)
        rx = r.json()
        if 'work' in rx.keys():
            work = rx['work']
            logging.info("{}: Work generated: {}".format(datetime.now(), work))
        else:
            logging.info("{}: work not in keys, response from server: {}".format(datetime.now(), rx))
    except Exception as e:
        logging.info("{}: ERROR GENERATING WORK: {}".format(datetime.now(), e))
        pass

    return work

@guilhermelawless guilhermelawless added wontfix This will not be worked on and removed wontfix This will not be worked on labels Jul 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Documentation
Projects
None yet
Development

No branches or pull requests

1 participant