コード例 #1
0
def profiling(name_list):
    stm = DPay()
    set_shared_dpay_instance(stm)
    del stm
    print("start")
    for name in name_list:
        print("account: %s" % (name))
        acc = Account(name)
        max_index = acc.virtual_op_count()
        print(max_index)
        stopTime = datetime(2018, 4, 22, 0, 0, 0)
        hist_elem = None
        for h in acc.history_reverse(stop=stopTime):
            hist_elem = h
        print(hist_elem)
    print("blockchain")
    blockchain_object = Blockchain()
    current_num = blockchain_object.get_current_block_num()
    startBlockNumber = current_num - 20
    endBlockNumber = current_num
    block_elem = None
    for o in blockchain_object.stream(start=startBlockNumber,
                                      stop=endBlockNumber):
        print("block %d" % (o["block_num"]))
        block_elem = o
    print(block_elem)
コード例 #2
0
 def setup(self):
     self.prefix = u"BEX"
     self.default_prefix = u"DWB"
     self.wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
     self.ref_block_num = 34294
     self.ref_block_prefix = 3707022213
     self.expiration = "2016-04-06T08:29:27"
     self.stm = DPay(offline=True)
コード例 #3
0
def profiling(node,
              name_list,
              shared_instance=True,
              clear_acc_cache=False,
              clear_all_cache=True):
    print("shared_instance %d clear_acc_cache %d clear_all_cache %d" %
          (shared_instance, clear_acc_cache, clear_all_cache))
    if not shared_instance:
        stm = DPay(node=node)
        print(str(stm))
    else:
        stm = None
    acc_dict = {}
    for name in name_list:
        acc = Account(name, dpay_instance=stm)
        acc_dict[name] = acc
        if clear_acc_cache:
            acc.clear_cache()
        acc_dict = {}
    if clear_all_cache:
        clear_cache()
    if not shared_instance:
        del stm.rpc
コード例 #4
0
ファイル: hf20_testnet.py プロジェクト: dpays/dpay-cli
from __future__ import print_function
from __future__ import unicode_literals
import sys
from datetime import datetime, timedelta
import time
import io
import logging

from dpaycli.blockchain import Blockchain
from dpaycli.block import Block
from dpaycli.account import Account
from dpaycli.amount import Amount
from dpaycligraphenebase.account import PasswordKey, PrivateKey, PublicKey
from dpaycli.dpay import DPay
from dpaycli.utils import parse_time, formatTimedelta
from dpaycliapi.exceptions import NumRetriesReached
from dpaycli.nodelist import NodeList
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

if __name__ == "__main__":
    # stm = DPay(node="https://testnet.timcliff.com/")
    # stm = DPay(node="https://testnet.dpaydev.com")
    stm = DPay(node="https://api.dpays.io")
    stm.wallet.unlock(pwd="pwd123")

    account = Account("dpayclibot", dpay_instance=stm)
    print(account.get_voting_power())

    account.transfer("holger80", 0.001, "BBD", "test")
コード例 #5
0
ファイル: using_steem_offline.py プロジェクト: dpays/dpay-cli
from dpaycli.transactionbuilder import TransactionBuilder
from dpaycligraphenebase.account import PasswordKey, PrivateKey, PublicKey
from dpaycli.dpay import DPay
from dpaycli.utils import parse_time, formatTimedelta
from dpaycliapi.exceptions import NumRetriesReached
from dpaycli.nodelist import NodeList
from dpayclibase.transactions import getBlockParams

log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

# example wif
wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"

if __name__ == "__main__":
    stm_online = DPay()
    ref_block_num, ref_block_prefix = getBlockParams(stm_online)
    print("ref_block_num %d - ref_block_prefix %d" %
          (ref_block_num, ref_block_prefix))

    stm = DPay(offline=True)

    op = operations.Transfer({
        'from': 'dpayclibot',
        'to': 'holger80',
        'amount': "0.001 BBD",
        'memo': ""
    })
    tb = TransactionBuilder(dpay_instance=stm)

    tb.appendOps([op])
コード例 #6
0
from dpaycli.blockchain import Blockchain
from dpaycli.block import Block
from dpaycli.dpay import DPay
from dpaycli.utils import parse_time, formatTimedelta
from dpaycli.nodelist import NodeList

log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

if __name__ == "__main__":
    node_setup = 1
    how_many_hours = 1
    nodes = NodeList()
    if node_setup == 0:
        stm = DPay(node=nodes.get_nodes(normal=True, wss=True), num_retries=10)
        max_batch_size = None
        threading = False
        thread_num = 8
    elif node_setup == 1:
        stm = DPay(node=nodes.get_nodes(normal=True, wss=True), num_retries=10)
        max_batch_size = None
        threading = True
        thread_num = 16
    elif node_setup == 2:
        stm = DPay(node=nodes.get_nodes(appbase=False, https=False),
                   num_retries=10)
        max_batch_size = None
        threading = True
        thread_num = 16
    blockchain = Blockchain(dpay_instance=stm)
コード例 #7
0
        stm = None
    acc_dict = {}
    for name in name_list:
        acc = Account(name, dpay_instance=stm)
        acc_dict[name] = acc
        if clear_acc_cache:
            acc.clear_cache()
        acc_dict = {}
    if clear_all_cache:
        clear_cache()
    if not shared_instance:
        del stm.rpc


if __name__ == "__main__":
    stm = DPay()
    print("Shared instance: " + str(stm))
    set_shared_dpay_instance(stm)
    b = Blockchain()
    account_list = []
    for a in b.get_all_accounts(limit=500):
        account_list.append(a)
    shared_instance = False
    clear_acc_cache = False
    clear_all_cache = False
    node = "https://api.dpays.io"
    n = 3
    for i in range(1, n + 1):
        print("%d of %d" % (i, n))
        profiling(node,
                  account_list,
コード例 #8
0
ファイル: op_on_testnet.py プロジェクト: dpays/dpay-cli
from dpaycligraphenebase.account import PasswordKey, PrivateKey, PublicKey
from dpaycli.dpay import DPay
from dpaycli.utils import parse_time, formatTimedelta
from dpaycliapi.exceptions import NumRetriesReached
from dpaycli.nodelist import NodeList
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

password = "******"
username = "******"
useWallet = False
walletpassword = "******"

if __name__ == "__main__":
    testnet_node = "https://testnet.dpay.vc"
    stm = DPay(node=testnet_node)
    prefix = stm.prefix
    # curl --data "username=username&password=secretPassword" https://testnet.dpay.vc/create
    if useWallet:
        stm.wallet.wipe(True)
        stm.wallet.create(walletpassword)
        stm.wallet.unlock(walletpassword)
    active_key = PasswordKey(username, password, role="active", prefix=prefix)
    owner_key = PasswordKey(username, password, role="owner", prefix=prefix)
    posting_key = PasswordKey(username,
                              password,
                              role="posting",
                              prefix=prefix)
    memo_key = PasswordKey(username, password, role="memo", prefix=prefix)
    active_pubkey = active_key.get_public_key()
    owner_pubkey = owner_key.get_public_key()
コード例 #9
0
    dpaycli_test.setup()
    dpay_times = []
    dpaycli_times = []
    loops = 50
    for i in range(0, loops):
        print(i)
        opDPay = dpayOperations.Transfer(**{
            "from": "foo",
            "to": "baar",
            "amount": "111.110 BEX",
            "memo": "Fooo"
        })
        opDPayCli = operations.Transfer(**{
            "from": "foo",
            "to": "baar",
            "amount": Amount("111.110 BEX", dpay_instance=DPay(offline=True)),
            "memo": "Fooo"
        })

        t_s, t_v = dpay_test.doit(ops=opDPay)
        dpay_times.append([t_s, t_v])

        t_s, t_v = dpaycli_test.doit(ops=opDPayCli)
        dpaycli_times.append([t_s, t_v])

    dpay_dt = [0, 0]
    dpaycli_dt = [0, 0]
    for i in range(0, loops):
        dpay_dt[0] += dpay_times[i][0]
        dpay_dt[1] += dpay_times[i][1]
        dpaycli_dt[0] += dpaycli_times[i][0]
コード例 #10
0
def benchmark_node(node, how_many_minutes=10, how_many_seconds=30):
    block_count = 0
    history_count = 0
    access_time = 0
    follow_time = 0
    blockchain_version = u'0.0.0'
    successful = True
    error_msg = None
    start_total = timer()
    max_batch_size = None
    threading = False
    thread_num = 16

    authorpermvoter = u"@gtg/dpay-pressure-4-need-for-speed|gandalf"
    [author, permlink, voter] = resolve_authorpermvoter(authorpermvoter)
    authorperm = construct_authorperm(author, permlink)
    last_block_id = 19273700
    try:
        stm = DPay(node=node, num_retries=3, num_retries_call=3, timeout=30)
        blockchain = Blockchain(dpay_instance=stm)
        blockchain_version = stm.get_blockchain_version()

        last_block = Block(last_block_id, dpay_instance=stm)

        stopTime = last_block.time() + timedelta(seconds=how_many_minutes * 60)
        total_transaction = 0

        start = timer()
        for entry in blockchain.blocks(start=last_block_id,
                                       max_batch_size=max_batch_size,
                                       threading=threading,
                                       thread_num=thread_num):
            block_no = entry.identifier
            block_count += 1
            if "block" in entry:
                trxs = entry["block"]["transactions"]
            else:
                trxs = entry["transactions"]

            for tx in trxs:
                for op in tx["operations"]:
                    total_transaction += 1
            if "block" in entry:
                block_time = parse_time(entry["block"]["timestamp"])
            else:
                block_time = parse_time(entry["timestamp"])

            if block_time > stopTime:
                last_block_id = block_no
                break
            if timer() - start > how_many_seconds or quit_thread:
                break
    except NumRetriesReached:
        error_msg = 'NumRetriesReached'
        block_count = -1
    except KeyboardInterrupt:
        error_msg = 'KeyboardInterrupt'
        # quit = True
    except Exception as e:
        error_msg = str(e)
        block_count = -1

    try:
        stm = DPay(node=node, num_retries=3, num_retries_call=3, timeout=30)
        account = Account("gtg", dpay_instance=stm)
        blockchain_version = stm.get_blockchain_version()

        start = timer()
        for acc_op in account.history_reverse(batch_size=100):
            history_count += 1
            if timer() - start > how_many_seconds or quit_thread:
                break
    except NumRetriesReached:
        error_msg = 'NumRetriesReached'
        history_count = -1
        successful = False
    except KeyboardInterrupt:
        error_msg = 'KeyboardInterrupt'
        history_count = -1
        successful = False
        # quit = True
    except Exception as e:
        error_msg = str(e)
        history_count = -1
        successful = False

    try:
        stm = DPay(node=node, num_retries=3, num_retries_call=3, timeout=30)
        account = Account("gtg", dpay_instance=stm)
        blockchain_version = stm.get_blockchain_version()

        start = timer()
        Vote(authorpermvoter, dpay_instance=stm)
        stop = timer()
        vote_time = stop - start
        start = timer()
        Comment(authorperm, dpay_instance=stm)
        stop = timer()
        comment_time = stop - start
        start = timer()
        Account(author, dpay_instance=stm)
        stop = timer()
        account_time = stop - start
        start = timer()
        account.get_followers()
        stop = timer()
        follow_time = stop - start
        access_time = (vote_time + comment_time + account_time +
                       follow_time) / 4.0
    except NumRetriesReached:
        error_msg = 'NumRetriesReached'
        access_time = -1
    except KeyboardInterrupt:
        error_msg = 'KeyboardInterrupt'
        # quit = True
    except Exception as e:
        error_msg = str(e)
        access_time = -1
    return {
        'successful': successful,
        'node': node,
        'error': error_msg,
        'total_duration': timer() - start_total,
        'block_count': block_count,
        'history_count': history_count,
        'access_time': access_time,
        'follow_time': follow_time,
        'version': blockchain_version
    }
コード例 #11
0
            quit_thread = True
            print("benchmark aborted.")
    else:
        for node in nodes:
            print("Current node:", node)
            result = benchmark_node(node, how_many_minutes, how_many_seconds)
            results.append(result)
    for result in results:
        t2.add_row([result["node"], result["version"]])
    print(t2)
    print("\n")

    sortedList = sorted(results,
                        key=lambda self: self["history_count"],
                        reverse=True)
    for result in sortedList:
        if result["successful"]:
            t.add_row([
                result["node"], result["block_count"], result["history_count"],
                ("%.2f" % (result["access_time"]))
            ])
            working_nodes.append(result["node"])
    print(t)
    print("\n")
    print("Total benchmark time: %.2f s\n" % (timer() - benchmark_time))
    if set_default_nodes:
        stm = DPay(offline=True)
        stm.set_default_nodes(working_nodes)
    else:
        print("dpay set nodes " + str(working_nodes))
コード例 #12
0
import io
import logging

from dpaycli.blockchain import Blockchain
from dpaycli.block import Block
from dpaycli.account import Account
from dpaycli.amount import Amount
from dpaycligraphenebase.account import PasswordKey, PrivateKey, PublicKey
from dpaycli.dpay import DPay
from dpaycli.utils import parse_time, formatTimedelta
from dpaycliapi.exceptions import NumRetriesReached
from dpaycli.nodelist import NodeList
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)


if __name__ == "__main__":
    stm = DPay(node=["https://testnet.dpaydev.com"],
                custom_chains={"TESTNETHF20":
                               {'chain_assets':
                                [
                                    {"asset": "@@000000013", "symbol": "BBD", "precision": 3, "id": 0},
                                    {"asset": "@@000000021", "symbol": "BEX", "precision": 3, "id": 1},
                                    {"asset": "@@000000037", "symbol": "VESTS", "precision": 6, "id": 2}
                                ],
                                'chain_id': '46d82ab7d8db682eb1959aed0ada039a6d49afa1602491f93dde9cac3e8e6c32',
                                'min_version': '0.20.0',
                                'prefix': 'TST'}})
    print(stm.get_blockchain_version())
    print(stm.get_config()["DPAY_CHAIN_ID"])
コード例 #13
0
ファイル: cache_performance.py プロジェクト: dpays/dpay-cli
    return opcount, total_duration


if __name__ == "__main__":
    node_setup = 1
    threading = True
    thread_num = 8
    timeout = 10
    nodes = NodeList()
    nodes.update_nodes(weights={"block": 1})
    node_list = nodes.get_nodes()[:5]

    vote_result = []
    duration = []

    stm = DPay(node=node_list, timeout=timeout)
    b = Blockchain(dpay_instance=stm)
    block = b.get_current_block()
    block.set_cache_auto_clean(False)
    opcount, total_duration = stream_votes(stm, threading, thread_num)
    print("Finished!")
    block.set_cache_auto_clean(True)
    cache_len = len(list(block._cache))
    start_time = time.time()
    block.clear_cache_from_expired_items()
    clear_duration = time.time() - start_time
    time.sleep(5)
    cache_len_after = len(list(block._cache))
    start_time = time.time()
    print(str(block._cache))
    clear_duration2 = time.time() - start_time
コード例 #14
0
    return opcount, total_duration


if __name__ == "__main__":
    node_setup = 1
    threading = True
    thread_num = 8
    timeout = 10
    nodes = NodeList()
    nodes.update_nodes(weights={"block": 1})
    node_list_wss = nodes.get_nodes(https=False)[:5]
    node_list_https = nodes.get_nodes(wss=False)[:5]

    vote_result = []
    duration = []
    stm_wss = DPay(node=node_list_wss, timeout=timeout)
    stm_https = DPay(node=node_list_https, timeout=timeout)
    print("Without threading wss")
    opcount_wot_wss, total_duration_wot_wss = stream_votes(stm_wss, False, 8)
    print("Without threading https")
    opcount_wot_https, total_duration_wot_https = stream_votes(
        stm_https, False, 8)
    if threading:
        print("\n Threading with %d threads is activated now." % thread_num)

    stm = DPay(node=node_list_wss, timeout=timeout)
    opcount_wss, total_duration_wss = stream_votes(stm, threading, thread_num)
    opcount_https, total_duration_https = stream_votes(stm, threading,
                                                       thread_num)
    print("Finished!")