Skip to content

Commit

Permalink
Asset protobuf consistency closes #58 closes #57
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankC01 committed Apr 30, 2018
1 parent 5217b24 commit b3f545e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 26 deletions.
10 changes: 5 additions & 5 deletions cli/hashblock_cli/hbasset.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def _accept(candidate, public_key):
for vote in candidate.votes:
print(" voter {} => {}".format(
vote.public_key,
"accept" if vote.vote is AssetVote.ACCEPT else "reject"))
"accept" if vote.vote is AssetVote.VOTE_ACCEPT else "reject"))
elif args.format == 'csv':
writer = csv.writer(sys.stdout, quoting=csv.QUOTE_ALL)
writer.writerow(['PROPOSAL_ID', 'SYSTEM', 'KEY', 'VALUE', 'SKU'])
Expand Down Expand Up @@ -429,7 +429,7 @@ def _create_propose_txn(signer, asset, dimension, asset_addr, proposal_type):
payload = AssetPayload(
data=proposal.SerializeToString(),
dimension=dimension,
action=AssetPayload.PROPOSE)
action=AssetPayload.ACTION_PROPOSE)

return _make_txn(signer, dimension, asset_addr, payload)

Expand All @@ -438,12 +438,12 @@ def _create_vote_txn(signer, proposal_id, dimension, vote_value):
"""Creates an individual hashblock_resource transaction for voting on a
proposal for a particular asset. The proposal_id is the asset address
"""
vote_action = AssetPayload.VOTE
vote_action = AssetPayload.ACTION_VOTE

if vote_value == 'accept':
vote_id = AssetVote.ACCEPT
vote_id = AssetVote.VOTE_ACCEPT
elif vote_value == 'reject':
vote_id = AssetVote.REJECT
vote_id = AssetVote.VOTE_REJECT
elif vote_value == 'rescind':
vote_id = AssetVote.VOTE_UNSET
vote_action = AssetPayload.ACTION_UNSET
Expand Down
13 changes: 7 additions & 6 deletions families/asset/hashblock_asset/processor/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ def apply(self, transaction, context):
raise InvalidTransaction(
'{} is not authorized to change asset'.format(public_key))

if asset_payload.action == AssetPayload.PROPOSE:
if asset_payload.action == AssetPayload.ACTION_PROPOSE:
return self._apply_proposal(
public_key,
asset_payload.data,
context)
elif asset_payload.action == AssetPayload.VOTE:
elif asset_payload.action == AssetPayload.ACTION_VOTE:
return self._apply_vote(
public_key,
auth_keys,
Expand All @@ -114,7 +114,8 @@ def apply(self, transaction, context):
def _apply_proposal(self, public_key, proposal_data, context):
asset_proposal = AssetProposal()
asset_proposal.ParseFromString(proposal_data)

LOGGER.debug(
"Processing proposal for type {}".format(asset_proposal.type))
self.asset_type.asset_from_proposal(asset_proposal)
proposal_id = (self.asset_type.asset_address)

Expand All @@ -134,7 +135,7 @@ def _apply_proposal(self, public_key, proposal_data, context):

record = AssetCandidate.VoteRecord(
public_key=public_key,
vote=AssetVote.ACCEPT)
vote=AssetCandidate.VoteRecord.VOTE_ACCEPT)
asset_candidates.candidates.add(
proposal_id=proposal_id,
proposal=asset_proposal,
Expand Down Expand Up @@ -227,9 +228,9 @@ def _apply_vote(self, public_key, authorized_keys, vote_data, context):
accepted_count = 0
rejected_count = 0
for vote_record in candidate.votes:
if vote_record.vote == AssetVote.ACCEPT:
if vote_record.vote == AssetVote.VOTE_ACCEPT:
accepted_count += 1
elif vote_record.vote == AssetVote.REJECT:
elif vote_record.vote == AssetVote.VOTE_REJECT:
rejected_count += 1

LOGGER.debug(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def create_proposal_transaction(self, asset, dimension, nonce):
else AssetProposal.RESOURCE,
nonce=nonce)
payload = AssetPayload(
action=AssetPayload.PROPOSE,
action=AssetPayload.ACTION_PROPOSE,
dimension=dimension,
data=proposal.SerializeToString())

Expand All @@ -84,7 +84,7 @@ def create_vote_transaction(self, proposal_id, asset, dimension, vote):
proposal_id=proposal_id,
vote=vote)
payload = AssetPayload(
action=AssetPayload.VOTE,
action=AssetPayload.ACTION_VOTE,
dimension=dimension,
data=avote.SerializeToString())

Expand Down
12 changes: 6 additions & 6 deletions families/asset/tests/test_tp_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def _build_first_candidate(self, pkey, asset, dimension):
nonce="somenonce")
record = AssetCandidate.VoteRecord(
public_key=pkey,
vote=AssetVote.ACCEPT)
vote=AssetVote.VOTE_ACCEPT)
return AssetCandidates(candidates=[
AssetCandidate(
proposal_id=proposal_id,
Expand Down Expand Up @@ -237,7 +237,7 @@ def _test_valid_accept_vote(self, asset, dimension):
proposal_id = self._setup_vote(
asset,
dimension,
AssetVote.ACCEPT,
AssetVote.VOTE_ACCEPT,
VOTER2)
self._expect_set(proposal_id, x)
self._expect_add_event(proposal_id)
Expand All @@ -248,7 +248,7 @@ def _test_valid_reject_vote(self, asset, dimension):
self._setup_vote(
asset,
dimension,
AssetVote.REJECT,
AssetVote.VOTE_REJECT,
VOTER2)
self._set_empty_candidates(dimension)
self._expect_ok()
Expand Down Expand Up @@ -309,7 +309,7 @@ def _build_disjoint_candidate(self, proposal_id, voter, asset, dimension):
nonce="somenonce")
record = AssetCandidate.VoteRecord(
public_key=voter,
vote=AssetVote.ACCEPT)
vote=AssetVote.VOTE_ACCEPT)
return AssetCandidates(candidates=[
AssetCandidate(
proposal_id=proposal_id,
Expand Down Expand Up @@ -340,7 +340,7 @@ def test_vote_proposal_id_not_found(self):
uproposal_id,
self.unit,
Address.DIMENSION_UNIT,
AssetVote.ACCEPT)
AssetVote.VOTE_ACCEPT)
self._get_setting(Address.DIMENSION_UNIT)
self._expect_get(
_asset_addr.candidates(Address.DIMENSION_UNIT),
Expand All @@ -357,6 +357,6 @@ def test_vote_dupe_voter(self):
self._setup_vote(
self.unit,
Address.DIMENSION_UNIT,
AssetVote.ACCEPT,
AssetVote.VOTE_ACCEPT,
self._public_key)
self._expect_invalid_transaction()
2 changes: 1 addition & 1 deletion families/asset/tests/test_tp_asset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ version: "2.1"
services:

asset-processor:
image: hashblock-dev-asset-tp:latest
image: hashblock-dev-generic-tp:latest
container_name: hashblock-asset-dev-tp
volumes:
- ../../..:/project/hashblock-exchange
Expand Down
12 changes: 6 additions & 6 deletions protos/asset.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ message AssetPayload {
ACTION_UNSET = 0;

// A proposal action - data will be a AssetProposal
PROPOSE = 1;
ACTION_PROPOSE = 1;

// A vote action - data will be a AssetVote
VOTE = 2;
ACTION_VOTE = 2;
}
// The action of this payload
Action action = 1;
Expand Down Expand Up @@ -88,8 +88,8 @@ message AssetProposal {
message AssetVote {
enum Vote {
VOTE_UNSET = 0;
ACCEPT = 1;
REJECT = 2;
VOTE_ACCEPT = 1;
VOTE_REJECT = 2;
}

// The id of the proposal being voted on
Expand All @@ -107,8 +107,8 @@ message AssetCandidate {
message VoteRecord {
enum Vote {
VOTE_UNSET = 0;
ACCEPT = 1;
REJECT = 2;
VOTE_ACCEPT = 1;
VOTE_REJECT = 2;
}
// The public key of the voter
string public_key = 1;
Expand Down

0 comments on commit b3f545e

Please sign in to comment.