SOLVED! Beem trouble

in #beem4 years ago (edited)

Airdrop unable

Genkin {GNK} and Milcendo {MCD} snapshot done manually.

No errors though

Did change the code using the latest version of Beem 0.23.6 and it does run without any error. Yet, no Ducat is being transferred so far. The airdrop lists are ready to go, but the code seems not.

UPDATE

Just fixed it, phew. First comes the SYMBOL, then the 'to' address. But... All this time I used the DCT ticker, instead of DUCAT. Well, fixed it now, so the real Airdrop now soon can be done. DUCAT for those who held Genkin and Milcendo...

file gohivego.py

#
# Automated Token Emission, ATE, for HIVE
# A fork from the former Steem Engine Airdrop project, by The Marky Mark 
# Version 202005121806 - 0.0.2.3 - beta, by Oaldamster
# 

# Import some Python modules

import csv
import json
import sys
import time
import os

# Import the Beem Hive module by Holger80

from beem import Hive
from beem.nodelist import NodeList
from beem.account import Account
from beem.exceptions import AccountDoesNotExistsException
from beem.instance import set_shared_hive_instance

# Some global variables

config = {}
user_list = [] 

# Get the Current Working Directory
# Assume files are stored relative from here

current_Dir = os.getcwd() + "/"
print (current_Dir) 
load_Configfile = current_Dir + (sys.argv[1])

# Load the config file

def load_config():  
    global config

    if len(sys.argv) == 1:
        # Instead of this create a default?
        print("ERROR: Please specify a config file")
        quit()
    else:
        print (load_Configfile)

    try:
        with open(load_Configfile) as config_file:
            config = json.load(config_file)
            print(f"Loading emission file: {config['loadfile']}\n")

    except:
        print("Unable to open configuration file")
        quit()                 

# Load the user list to airdrop to

def load_users():
    global user_list
    
    # Add Try etc later
    if config['loadfile']:  
        get_file = current_Dir + config['data_path'] + config['data_file'] + "-" + config['token'] + "." + config['data_file_ext']
        try:
            with open(get_file) as user_file:   
                reader = csv.reader(user_file)
                user_list = list(reader)
                print("Loaded emission file.\n")
            
        except:
            print("Unable to open emission file")
            quit()

# Build from the data to store on the Hive blockchain           
            
def build_payload(user, amount):
    data = {}
    data['contractName'] = 'tokens'
    data['contractAction'] = config['mode']

    data['contractPayload'] = {}
     #For Hive it uses Symbol first
    data['contractPayload']['symbol'] = config['token'].upper()
    data['contractPayload']['to'] = user 
    data['contractPayload']['quantity'] = f"{amount}"
    data['contractPayload']['memo'] = config['memo']

    return data

# Hey Hoo, let's go! Send them Tokens

def send_tokens(haif, user, amount, retries=0):
    data = build_payload(user, amount)

    if not config['dry_run']:
        try:
            haif.custom_json('ssc-mainnet-hive', data,
                            required_auths=[config['account_name']])
        except:
            if retries < 3:
                send_tokens(haif, user, amount, retries=retries)
            else:
                print(f"Airdrop aborted at user: {user[0]}")
                quit()

# Prepare for launch, check for Dry Run.

def do_airdrop(haif):
    estimated_time = round((len(user_list) * config['delay']) / 60, 1)

    estimated_tokens = 0
    for user in user_list:
        estimated_tokens += float(user[1])

    print("Starting Airdrop\n")

    if config['dry_run']:
        print("DRY RUN! - Tokens will not be transfered.\n")
    print(f"Estimated Time: {estimated_time} minutes")
    print(f"Estimated Tokens Used: {estimated_tokens}")
    print("")

    for x in range(10, -1, -1):
        print(f"Starting in {x} seconds...", end='\r')
        time.sleep(1)
        sys.stdout.flush()

    for user in user_list:
        try:
            Account(user[0])
        except AccountDoesNotExistsException:
            print(f"Skipping user {user[0]} - Does not exist")
            continue

        print(f"Sending {user[1]} {config['token']} tokens to @{user[0]}")
        if not config['dry_run']:
            send_tokens(haif, user[0], user[1])

        time.sleep(config['delay'])

# The main file, ground control

def main():
    print("\n")

    load_config()
    load_users()
    
    # Nodelist  
    nodelist = NodeList()
    nodelist.update_nodes()
    nodes = nodelist.get_nodes(hive=True)
    # Direct node setup
    # haif = Hive(node=["https://api.hive.blog"])
    haif = Hive(node=nodes)
    haif.wallet.unlock(config['pw'])
    
    set_shared_hive_instance(haif)

    do_airdrop(haif)

# Start it all

if __name__ == '__main__':
    main()

config-dct.json

{
    "dry_run" : false,
    "account_name" : "oaldamster",
    "pw" : "password", 
    "token" : "ducat",
    "memo" : "Testing Airdrop.", 
    "issue_first" : false,
    "mode" : "transfer", 
    "loadfile" : true,
    "data_path" : "data/",
    "data_file" : "airdroptest",
    "data_file_ext" : "dat",
    "delay" : 10
}

airdroptest-ducat.dat

null,0.53135

Just a small amount for testing.

Have a great one!