This repository has been archived by the owner on Jan 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from scottbelden/promote_transaction
add promote_transaction_api
- Loading branch information
Showing
10 changed files
with
610 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) | ||
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), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.