-
Notifications
You must be signed in to change notification settings - Fork 126
add promote_transaction_api #127
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # coding=utf-8 | ||
| from __future__ import absolute_import, division, print_function, \ | ||
| unicode_literals | ||
|
|
||
| import filters as f | ||
| from iota import ( | ||
| Bundle, TransactionHash, Address, ProposedTransaction, BadApiResponse, | ||
| ) | ||
| from iota.commands import FilterCommand, RequestFilter | ||
| from iota.commands.core.check_consistency import CheckConsistencyCommand | ||
| from iota.commands.extended.send_transfer import SendTransferCommand | ||
| from iota.filters import Trytes | ||
|
|
||
| __all__ = [ | ||
| 'PromoteTransactionCommand', | ||
| ] | ||
|
|
||
|
|
||
| class PromoteTransactionCommand(FilterCommand): | ||
| """ | ||
| Executes ``promoteTransaction`` extended API command. | ||
| See :py:meth:`iota.api.Iota.promote_transaction` for more information. | ||
| """ | ||
| command = 'promoteTransaction' | ||
|
|
||
| def get_request_filter(self): | ||
| return PromoteTransactionRequestFilter() | ||
|
|
||
| def get_response_filter(self): | ||
| pass | ||
|
|
||
| def _execute(self, request): | ||
| depth = request['depth'] # type: int | ||
| min_weight_magnitude = request['minWeightMagnitude'] # type: int | ||
| transaction = request['transaction'] # type: TransactionHash | ||
|
|
||
| cc_response = CheckConsistencyCommand(self.adapter)(tails=[transaction]) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to use the new
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm... interesting. What do you think about this? class Helpers:
def __init__(self, adapter):
...Then The tradeoff is that helpers won't have access to an
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does that mean that the current def is_promotable(self, tail):
return self.api.check_consistency(tails=[tail])['state']To: from iota.commands.core.check_consistency import CheckConsistencyCommand
def is_promotable(self, tail):
return CheckConsistencyCommand(self.adapter)(tails=[tail])['state']I don't see a problem with that.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aye, I think that would... oh. Hm, we might end up with circular references that way. Eh, I guess we could import the commands locally in the helper methods. The alternative, I think, would be to create helper classes, similar to what we're doing for commands. That feels a bit cathedral-ish to me, though; I dunno.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I can foresee circular dependencies. I'm okay with keeping it as is (not using the helper call) for the moment until a later date. |
||
| if cc_response['state'] is False: | ||
| raise BadApiResponse( | ||
| 'Transaction {transaction} is not promotable. ' | ||
| 'You should reattach first.'.format(transaction=transaction) | ||
| ) | ||
|
|
||
| spam_transfer = ProposedTransaction( | ||
| address=Address(b''), | ||
| value=0, | ||
| ) | ||
|
|
||
| return SendTransferCommand(self.adapter)( | ||
| seed=spam_transfer.address, | ||
| depth=depth, | ||
| transfers=[spam_transfer], | ||
| minWeightMagnitude=min_weight_magnitude, | ||
| reference=transaction, | ||
| ) | ||
|
|
||
|
|
||
| class PromoteTransactionRequestFilter(RequestFilter): | ||
| def __init__(self): | ||
| super(PromoteTransactionRequestFilter, self).__init__({ | ||
| 'depth': f.Required | f.Type(int) | f.Min(1), | ||
| 'transaction': f.Required | Trytes(result_type=TransactionHash), | ||
|
|
||
| # Loosely-validated; testnet nodes require a different value than | ||
| # mainnet. | ||
| 'minWeightMagnitude': f.Required | f.Type(int) | f.Min(1), | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❔ Could we add a couple of unit tests for
GetTransactionsToApproveRequestFilter, related toreference?