Skip to content

Commit

Permalink
Improve class dealing and unittesting
Browse files Browse the repository at this point in the history
  • Loading branch information
xeroc committed Dec 12, 2018
1 parent 055635f commit 3e15f87
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 59 deletions.
7 changes: 4 additions & 3 deletions bitshares/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ class Account(GrapheneAccount):
"""

type_id = 2
amount_class = Amount
operations = operations
def define_classes(self):
self.type_id = 2
self.amount_class = Amount
self.operations = operations

@property
def call_positions(self):
Expand Down
8 changes: 3 additions & 5 deletions bitshares/amount.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ class Amount(GrapheneAmount):
Amount("15 GOLD") + Amount("0.5 GOLD")
"""

asset_class = Asset

def get_price_class(self):
# We cannot import Price directly due to cyclic dependencies
def define_classes(self):
from .price import Price

return Price
self.asset_class = Asset
self.price_class = Price
3 changes: 2 additions & 1 deletion bitshares/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class Asset(GrapheneAsset):
refreshed with ``Asset.refresh()``.
"""

type_id = 3
def define_classes(self):
self.type_id = 3

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down
6 changes: 4 additions & 2 deletions bitshares/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ class Block(GrapheneBlock):
"""

type_id = "-none-"
def define_classes(self):
self.type_id = "-none-"


@BlockchainInstance.inject
class BlockHeader(GrapheneBlockHeader):
type_id = "-none-"
def define_classes(self):
self.type_id = "-none-"
5 changes: 3 additions & 2 deletions bitshares/blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ class Blockchain(GrapheneBlockchain):
This class let's you deal with blockchain related data and methods.
"""

block_class = Block
operationids = operationids
def define_classes(self):
self.block_class = Block
self.operationids = operationids
5 changes: 3 additions & 2 deletions bitshares/committee.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ class Committee(GrapheneCommittee):
"""

type_id = 5
account_class = Account
def define_classes(self):
self.type_id = 5
self.account_class = Account
10 changes: 4 additions & 6 deletions bitshares/instance.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# -*- coding: utf-8 -*-
from graphenecommon.instance import (
BlockchainInstance as GrapheneBlockchainInstance,
SharedInstance,
)
from graphenecommon.instance import AbstractBlockchainInstanceProvider, SharedInstance


class BlockchainInstance(GrapheneBlockchainInstance):
class BlockchainInstance(AbstractBlockchainInstanceProvider):
""" This is a class that allows compatibility with previous
naming conventions
"""
Expand All @@ -14,7 +11,8 @@ def __init__(self, *args, **kwargs):
# Also allow 'bitshares_instance'
if kwargs.get("bitshares_instance"):
kwargs["blockchain_instance"] = kwargs["bitshares_instance"]
GrapheneBlockchainInstance.__init__(self, *args, **kwargs)
if kwargs.get("blockchain_instance"):
SharedInstance.instance = kwargs["blockchain_instance"]

def get_instance_class(self):
""" Should return the Chain instance class, e.g. `bitshares.BitShares`
Expand Down
16 changes: 12 additions & 4 deletions bitshares/memo.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Memo(GrapheneMemo):
from bitshares.memo import Memo
m = Memo("bitshareseu", "wallet.xeroc")
m.blockchain.wallet.unlock("secret")
m.unlock_wallet("secret")
enc = (m.encrypt("foobar"))
print(enc)
>> {'nonce': '17329630356955254641', 'message': '8563e2bb2976e0217806d642901a2855'}
Expand All @@ -47,6 +47,14 @@ class Memo(GrapheneMemo):
"""

account_class = Account
privatekey_class = PrivateKey
publickey_class = PublicKey
MESSAGE_SPLIT = (
"-----BEGIN BITSHARES SIGNED MESSAGE-----",
"-----BEGIN META-----",
"-----BEGIN SIGNATURE-----",
"-----END BITSHARES SIGNED MESSAGE-----",
)

def define_classes(self):
self.account_class = Account
self.privatekey_class = PrivateKey
self.publickey_class = PublicKey
5 changes: 3 additions & 2 deletions bitshares/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@

@BlockchainInstance.inject
class Message(GrapheneMessage):
account_class = Account
publickey_class = PublicKey
def define_classes(self):
self.account_class = Account
self.publickey_class = PublicKey
5 changes: 3 additions & 2 deletions bitshares/price.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ class Price(GraphenePrice):
"""

amount_class = Amount
asset_class = Asset
def define_classes(self):
self.amount_class = Amount
self.asset_class = Asset

@property
def market(self):
Expand Down
10 changes: 6 additions & 4 deletions bitshares/proposal.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ class Proposal(GrapheneProposal):
"""

type_id = 10
account_class = Account
def define_classes(self):
self.type_id = 10
self.account_class = Account


@BlockchainInstance.inject
Expand All @@ -28,5 +29,6 @@ class Proposals(GrapheneProposals):
:param bitshares blockchain_instance: BitShares() instance to use when accesing a RPC
"""

account_class = Account
proposal_class = Proposal
def define_classes(self):
self.account_class = Account
self.proposal_class = Proposal
24 changes: 13 additions & 11 deletions bitshares/transactionbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ class ProposalBuilder(GrapheneProposalBuilder):
:param instance blockchain_instance: Blockchain instance
"""

operation_class = Operation
operations = operations
account_class = Account
def define_classes(self):
self.operation_class = Operation
self.operations = operations
self.account_class = Account


@BlockchainInstance.inject
Expand All @@ -46,11 +47,12 @@ class TransactionBuilder(GrapheneTransactionBuilder):
operations and signers.
"""

account_class = Account
asset_class = Asset
operation_class = Operation
operations = operations
privatekey_class = PrivateKey
publickey_class = PublicKey
signed_transaction_class = Signed_Transaction
amount_class = Amount
def define_classes(self):
self.account_class = Account
self.asset_class = Asset
self.operation_class = Operation
self.operations = operations
self.privatekey_class = PrivateKey
self.publickey_class = PublicKey
self.signed_transaction_class = Signed_Transaction
self.amount_class = Amount
7 changes: 4 additions & 3 deletions bitshares/vesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Vesting(GrapheneVesting):
"""

type_id = 13
account_class = Account
amount_class = Amount
def define_classes(self):
self.type_id = 13
self.account_class = Account
self.amount_class = Amount
9 changes: 5 additions & 4 deletions bitshares/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from .instance import BlockchainInstance


class Wallet(GrapheneWallet, BlockchainInstance):
chaininstance_class = BlockchainInstance
default_key_store_app_name = "bitshares"
privatekey_class = PrivateKey
@BlockchainInstance.inject
class Wallet(GrapheneWallet):
def define_classes(self):
self.default_key_store_app_name = "bitshares"
self.privatekey_class = PrivateKey
10 changes: 6 additions & 4 deletions bitshares/witness.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ class Witness(GrapheneWitness):
"""

account_class = Account
type_ids = [6, 2]
def define_classes(self):
self.account_class = Account
self.type_ids = [6, 2]


@BlockchainInstance.inject
Expand All @@ -32,5 +33,6 @@ class Witnesses(GrapheneWitnesses):
accesing a RPC
"""

account_class = Account
witness_class = Witness
def define_classes(self):
self.account_class = Account
self.witness_class = Witness
10 changes: 6 additions & 4 deletions bitshares/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ class Worker(GrapheneWorker):
"""

account_class = Account
type_id = 14
def define_classes(self):
self.account_class = Account
self.type_id = 14


@BlockchainInstance.inject
Expand All @@ -28,5 +29,6 @@ class Workers(GrapheneWorkers):
accesing a RPC
"""

account_class = Account
worker_class = Worker
def define_classes(self):
self.account_class = Account
self.worker_class = Worker

0 comments on commit 3e15f87

Please sign in to comment.