def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.ppy = PeerPlays(nobroadcast=True, wif=[wif]) set_shared_peerplays_instance(self.ppy) self.ppy.set_default_account("init0") self.mymock()
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.ppy = PeerPlays(nobroadcast=True, wif=[wif]) # from getpass import getpass # self.ppy.wallet.unlock(getpass()) set_shared_peerplays_instance(self.ppy) self.ppy.set_default_account("init0")
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.ppy = PeerPlays( nobroadcast=True, wif={ # Force signing with this key "active": wif }) set_shared_peerplays_instance(self.ppy) self.ppy.set_default_account("init0")
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.ppy = PeerPlays( nobroadcast=True, # We want to bundle many operations into a single transaction bundle=True, # Overwrite wallet to use this list of wifs only wif=[wif]) self.ppy.set_default_account("init0") set_shared_peerplays_instance(self.ppy)
def Finish(self, eventId, scores="test"): self.ppy = PeerPlays(self.config['node']) self.ppy.wallet.unlock(getpass()) self.proposal = self.ppy.proposal( proposer=self.config['proposer'], proposal_expiration=self.config['proposal_expiration']) self.ppy.event_update_status(event_id=eventId, status="finished", scores=scores, append_to=self.proposal) """scores=["2,1"], append_to=proposal)""" pprint(self.proposal.broadcast())
def Ppy(self): self.ppy = PeerPlays( self.config['node'], proposer=self.config['proposer'], proposal_expiration=self.config['proposal_expiration'], nobroadcast=False, bundle=True) if 'password' in self.config: self.ppy.wallet.unlock(self.config['password']) else: self.ppy.wallet.unlock(getpass()) return self.ppy
class Testcases(unittest.TestCase): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.ppy = PeerPlays( nobroadcast=True, # We want to bundle many operations into a single transaction bundle=True, # Overwrite wallet to use this list of wifs only wif=[wif]) self.ppy.set_default_account("init0") set_shared_peerplays_instance(self.ppy) def test_account(self): Account("witness-account") Account("1.2.3") asset = Asset("1.3.0") symbol = asset["symbol"] account = Account("witness-account", full=True) self.assertEqual(account.name, "witness-account") self.assertEqual(account["name"], account.name) self.assertEqual(account["id"], "1.2.1") self.assertIsInstance(account.balance("1.3.0"), Amount) self.assertIsInstance(account.balance({"symbol": symbol}), Amount) self.assertIsInstance(account.balances, list) for h in account.history(limit=1): pass # BlockchainObjects method account.cached = False self.assertTrue(account.items()) account.cached = False self.assertIn("id", account) account.cached = False self.assertEqual(account["id"], "1.2.1") self.assertEqual(str(account), "<Account 1.2.1>") self.assertIsInstance(Account(account), Account) def test_account_upgrade(self): account = Account("witness-account") tx = account.upgrade() ops = tx["operations"] op = ops[0][1] self.assertEqual(len(ops), 1) self.assertEqual(getOperationNameForId(ops[0][0]), "account_upgrade") self.assertTrue(op["upgrade_to_lifetime_member"]) self.assertEqual( op["account_to_upgrade"], "1.2.1", )
def InProgress(self, eventIds): self.ppy = PeerPlays(self.config['node']) self.ppy.wallet.unlock(getpass()) self.proposal = self.ppy.proposal( proposer=self.config['proposer'], proposal_expiration=self.config['proposal_expiration']) eventIds = eventIds.replace(' ', '') eventIds = eventIds.split(',') for eventId in eventIds: print(eventId) self.ppy.event_update_status(event_id=eventId, status="in_progress", append_to=self.proposal) pprint(self.proposal.broadcast())
def CancelBmg(self, bmgIds): self.ppy = PeerPlays(self.config['node']) self.ppy.wallet.unlock(getpass()) self.proposal = self.ppy.proposal( proposer=self.config['proposer'], proposal_expiration=self.config['proposal_expiration']) bmgIds = bmgIds.replace(' ', '') bmgIds = bmgIds.split(',') for bmgId in bmgIds: print(bmgId) # self.ppy.event_update_status( self.ppy.betting_market_group_update(betting_market_group_id=bmgId, status="canceled", append_to=self.proposal) pprint(self.proposal.broadcast())
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.ppy = PeerPlays( nobroadcast=True, ) set_shared_peerplays_instance(self.ppy)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.ppy = PeerPlays( nobroadcast=True, # this account creates the proposal # proposer="init2", # Proposal needs to be approve within 1 hour # proposal_expiration=60 * 60 * 24 * 14, # We want to bundle many operations into a single transaction bundle=True, # Overwrite wallet to use this list of wifs only wif=[wif] ) set_shared_peerplays_instance(self.ppy) self.ppy.set_default_account("init0")
class Testcases(unittest.TestCase): def __init__(self, *args, **kwargs): super(Testcases, self).__init__(*args, **kwargs) self.ppy = PeerPlays(nobroadcast=True, keys=wifs) set_shared_peerplays_instance(self.ppy) self.mockAccount() def mockAccount(self): _cache = ObjectCache(default_expiration=60 * 60 * 1, no_overwrite=True) for i in test_operation_dicts: _cache[i["id"]] = i BlockchainObject._cache = _cache def test_finalize(self): account = Account(account_id) op = operations.Transfer( **{ "fee": { "asset_id": "1.3.0", "amount": 1 }, "from": account_id, "to": '1.2.8', "amount": { "asset_id": "1.3.0", "amount": 1 } }) tx = self.ppy.finalizeOp(op, account, "active") self.assertEqual(len(tx["signatures"]), 1)
def new_func(ctx, *args, **kwargs): newoptions = ctx.obj newoptions.update(kwargsChain) ctx.peerplays = PeerPlays(**newoptions) ctx.blockchain = ctx.peerplays set_shared_peerplays_instance(ctx.peerplays) return ctx.invoke(f, *args, **kwargs)
def test__contains__(self): witnesses = Witnesses(peerplays_instance=PeerPlays()) """ self.assertIn("init0", witnesses) self.assertIn("1.2.7", witnesses) self.assertIn("1.6.1", witnesses) """ self.assertNotIn("faucet", witnesses)
def Settle(self, eventIds): eventIds = eventIds.replace(' ', '') eventIds = eventIds.split(',') self.ppy = PeerPlays(self.config['node'], proposer=self.config['proposer'], proposal_expiration=300, nobroadcast=False, bundle=True) self.ppy.wallet.unlock(getpass()) self.proposal = self.ppy.proposal( proposer=self.config['proposer'], proposal_expiration=self.config['proposal_expiration']) for eventId in eventIds: print(eventId) eventDetails = self.ppy.rpc.get_object(eventId) print(eventDetails) self._eventDetails = eventDetails eventName = eventDetails['name'][0][1] teams = eventName.split(' v ') bmgs = self.ppy.rpc.list_betting_market_groups(eventId) kBmg = 0 lenBmgs = len(bmgs) for bmg in bmgs: kBmg += 1 # pprint(bmg['id']) pprint(bmg) pprint(teams) print(' ') bms = self.ppy.rpc.list_betting_markets(bmg['id']) result = [] for k in range(len(bms)): print('Index: ', k) pprint(bms[k]) print(' ') result.append([bms[k]['id'], 'not_win']) option = input( str(kBmg) + '/' + str(lenBmgs) + 'Enter the winner index or most suitable bm index: ') result[int(option)][1] = 'win' self._result = result self._bmg = bmg self.ppy.betting_market_resolve(bmg['id'], result) os.system('clear') self.ppy.txbuffer.broadcast()
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) Lookup._clear() self.lookup = Lookup(network="unittests", sports_folder=os.path.join( os.path.dirname(os.path.realpath(__file__)), "bookiesports"), peerplays_instance=PeerPlays(nobroadcast=True, ))
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.ppy = PeerPlays(nobroadcast=True, ) set_shared_peerplays_instance(self.ppy) self.asset = Asset("1.3.0") self.symbol = self.asset["symbol"] self.precision = self.asset["precision"] self.asset2 = Asset("1.3.1")
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) Lookup._clear() Lookup(network="unittests", sports_folder=os.path.join( os.path.dirname(os.path.realpath(__file__)), "bookiesports"), peerplays_instance=PeerPlays(nobroadcast=True, )) self.lookup = LookupParticipants("AmericanFootball", "NFL_Teams_2017-18")
class Testcases(unittest.TestCase): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.ppy = PeerPlays( nobroadcast=True, # We want to bundle many operations into a single transaction bundle=True, # Overwrite wallet to use this list of wifs only wif=[wif], offline=True ) self.ppy.set_default_account("init0") set_shared_peerplays_instance(self.ppy) def test_get_pub_from_wif(self): self.assertEqual( self.ppy.wallet._get_pub_from_wif(wif), "PPY6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV" )
class Testcases(unittest.TestCase): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.ppy = PeerPlays( nobroadcast=True, # We want to bundle many operations into a single transaction bundle=True, # Overwrite wallet to use this list of wifs only wif=[wif] ) set_shared_peerplays_instance(self.ppy) self.ppy.set_default_account("init0") def test_fee_on_transfer(self): tx = self.ppy.transfer("init1", 1, "1.3.0", account="init0", fee_asset="1.3.1") op = tx["operations"][0][1] self.assertEqual(op["fee"]["asset_id"], "1.3.1") def test_feeasset_on_transfer(self): tx = self.ppy.transfer("init1", 1, "1.3.0", account="init0", fee_asset="BTF") op = tx["operations"][0][1] self.assertEqual(op["fee"]["asset_id"], "1.3.1")
def test_sync(self): self.lookup = Lookup( network="unittests", sports_folder=os.path.join( os.path.dirname(os.path.realpath(__file__)), "bookiesports" ), peerplays_instance=PeerPlays(nobroadcast=True) ) self.assertIsInstance(self.lookup, dict) self.assertIsInstance(self.lookup.peerplays, PeerPlays) self.assertTrue(self.lookup.peerplays.nobroadcast) self.assertIn("sports", self.lookup.data) self.assertTrue(self.lookup.data["sports"])
import datetime from pprint import pprint from peerplays import PeerPlays ppy = PeerPlays( # this account creates the proposal proposer="init0", # Proposal needs to be approve within 1 hour proposal_expiration=60 * 5, # For testing, set this to true nobroadcast=False, # We want to bundle many operations into a single transaction bundle=True, ) ppy.wallet.unlock("") ppy.betting_market_group_freeze( "1.20.0", True ) # Broadcast the whole transaction pprint( ppy.txbuffer.broadcast() )
import csv from getpass import getpass from datetime import datetime from pprint import pprint from peerplays import PeerPlays ppy = PeerPlays( # this account creates the proposal proposer="nathan", # Proposal needs to be approve within 24 hour, proposal_expiration=60 * 60 * 24, # For testing, set this to true nobroadcast=False, # We want to bundle many operations into a single transaction bundle=True, ) ppy.wallet.unlock(getpass()) result = {} relative_id_counter = 0 sport_relative_id_dict = {} # key is sport_name event_group_relative_id_dict = {} # key is event_group_name event_relative_id_dict = {} # key is event_name rules_relative_id_dict = {} # key is rules_name bmg_relative_id_dict = { } # key is "event_name bmg_name" since bmg_name itself is not unique bm_relative_id_dict = { } # key is "event_name bm_name" since bm_name itself is not unique with open("./peerplays-proposal-creation-source.csv", "rt") as csvfile:
from flask import Flask from flask import request from flask import Response from flask import make_response from flask import jsonify from flask import make_response from peerplays import PeerPlays from peerplaysbase import operations from peerplays.amount import Amount from peerplays.account import Account from peerplays.exceptions import * import bookie import time app = Flask(__name__) ppy = PeerPlays(nobroadcast=False) ppy.wallet.unlock(bookie.pwd) #Bookie related calls @app.route("/placeBets", methods=['POST']) def placeBets(): try: account = request.args.get("account") if account is None: return make_response( jsonify(error="Specify account in query params"), 500) body = request.get_json() response = [] for bet in body:
initial_pbsa = str( int(int(genesis["max_core_supply"]) * 0.66 - sum_distributed)) genesis["initial_balances"].append( dict(amount=initial_pbsa, asset_symbol="TEST", owner=address())) # Update sining keys of initial witnesses for i, _ in enumerate(genesis["initial_witness_candidates"]): genesis["initial_witness_candidates"][i]["block_signing_key"] = pubkey() # Other stuff genesis["initial_vesting_balances"] = [] genesis["initial_bts_accounts"] = [] genesis["max_core_supply"] = '400000000000000' # Read params from Alice network peerplays = PeerPlays("wss://node.peerplays.download") params = peerplays.rpc.get_object("2.0.0")["parameters"] # Missing Fees from Alice params["current_fees"]["parameters"].extend([ [50, {}], [51, { "fee": 100000 }], [52, { "fee": 100000 }], [53, { "fee": 100000 }], [54, {
from bos_incidents import factory from bos_incidents.validator import IncidentValidator, InvalidIncidentFormatException from bookiesports.normalize import IncidentsNormalizer, NotNormalizableException # default wifs key for testing wifs = [ "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3", "5KCBDTcyDqzsqehcb52tW5nU6pXife6V2rX9Yf7c3saYSzbDZ5W", ] wif = wifs[0] core_unit = "TEST" # peerplays instance peerplays = PeerPlays("wss://api.ppy-beatrice.blckchnd.com", keys=wifs, nobroadcast=True, num_retries=1) config = peerplays.config # Set defaults peerplays.set_default_account("init0") set_shared_peerplays_instance(peerplays) # Ensure we are not going to transaction anythin on chain! assert peerplays.nobroadcast # Setup base lookup lookup = Lookup( proposer="init0", blockchain_instance=peerplays, network="unittests",
from peerplays.rule import Rules from peerplays.proposal import Proposals from peerplays.eventgroup import EventGroups from peerplays.bettingmarketgroup import BettingMarketGroups from peerplays.bettingmarket import BettingMarkets from peerplaysbase.operationids import operations from bookied_sync.lookup import Lookup from bookied_sync.eventgroup import LookupEventGroup from bookied_sync.event import LookupEvent wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3" config = dict(nobroadcast=True) ppy = PeerPlays( keys=[wif], nobroadcast=config["nobroadcast"], num_retries=1, ) set_shared_peerplays_instance(ppy) lookup = Lookup( proposer="init0", blockchain_instance=ppy, network="unittests", sports_folder=os.path.join(os.path.dirname(os.path.realpath(__file__)), "bookiesports"), ) assert lookup.blockchain.nobroadcast # Setup custom Cache BlockchainObject._cache = ObjectCache(default_expiration=60 * 60 * 1, no_overwrite=True)
def new_func(ctx, *args, **kwargs): ctx.obj["offline"] = True ctx.peerplays = PeerPlays(**ctx.obj) ctx.blockchain = ctx.peerplays set_shared_peerplays_instance(ctx.peerplays) return ctx.invoke(f, *args, **kwargs)
import os import mock import unittest from pprint import pprint from peerplays import PeerPlays from bookied_sync.lookup import Lookup from bookied_sync.sport import LookupSport from peerplays.instance import set_shared_blockchain_instance import logging logging.basicConfig(level=logging.INFO) UNLOCK = "" ppy = PeerPlays(nobroadcast=False, blocking=True) set_shared_blockchain_instance(ppy) class Testcases(unittest.TestCase): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) Lookup._clear() Lookup( network="unittests", sports_folder=os.path.join( os.path.dirname(os.path.realpath(__file__)), "bookiesports"), peerplays_instance=ppy, ) self.lookup = LookupSport("AmericanFootball")
def get_peerplays(): return PeerPlays( environ.get('NODE_URI'), keys=wifs, nobroadcast=False )