-
Notifications
You must be signed in to change notification settings - Fork 6
Resend txn & Handle dropped txns #70 #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bshevchenko
wants to merge
1
commit into
DigixGlobal:develop
Choose a base branch
from
bshevchenko:develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,69 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Mutations | ||
| class ResendTransactionMutation < Types::Base::BaseMutation | ||
| description 'Given an old transaction, resend it with new parameters or gas prices' | ||
|
|
||
| argument :id, ID, | ||
| required: true, | ||
| description: 'ID of the transaction to be resent' | ||
| argument :transaction_hash, String, | ||
| required: true, | ||
| description: 'Transaction hash' | ||
| argument :transaction_object, Types::Scalar::JSONObject, | ||
| required: true, | ||
| description: 'The JSONified transaction data object' | ||
| argument :signed_transaction, String, | ||
| required: true, | ||
| description: 'Signed transaction in HEX format' | ||
|
|
||
| field :watched_transaction, Types::WatchedTransaction::WatchedTransactionType, | ||
| null: true, | ||
| description: 'Newly created transaction' | ||
| field :errors, [UserErrorType], | ||
| null: false, | ||
| description: <<~EOS | ||
| Mutation errors | ||
|
|
||
| Operation Errors: | ||
| - Previous transaction not found | ||
| - Unauthorized action | ||
| - Nonce is not the same as the previous | ||
| EOS | ||
|
|
||
| def resolve(id:, transaction_hash:, transaction_object:, signed_transaction:) | ||
| key = :watched_transaction | ||
|
|
||
| unless (old = WatchingTransaction.find_by(id: id)) | ||
| return form_error(key, 'transaction_object', 'Previous transaction not found') | ||
| end | ||
|
|
||
| attrs = { | ||
| txhash: transaction_hash, | ||
| transaction_object: transaction_object, | ||
| signed_transaction: signed_transaction | ||
| } | ||
|
|
||
| result, tx_or_errors = WatchingTransaction.resend( | ||
| context.fetch(:current_user, nil), | ||
| old, | ||
| attrs | ||
| ) | ||
|
|
||
| case result | ||
| when :unauthorized_action | ||
| form_error(key, 'id', 'Unauthorized action') | ||
| when :invalid_nonce | ||
| form_error(key, 'transaction_object', 'Nonce is not the same as the previous') | ||
| when :invalid_data | ||
| model_errors(key, tx_or_errors) | ||
| when :ok | ||
| model_result(key, tx_or_errors) | ||
| end | ||
| end | ||
|
|
||
| def self.authorized?(object, context) | ||
| super && context.fetch(:current_user, nil) | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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,55 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Mutations | ||
| class WatchTransactionMutation < Types::Base::BaseMutation | ||
| description 'Given a transaction, save it to the database to be resent' | ||
|
|
||
| argument :transaction_hash, String, | ||
| required: true, | ||
| description: 'Transaction hash' | ||
| argument :transaction_object, Types::Scalar::JSONObject, | ||
| required: true, | ||
| description: 'The JSONified transaction data object' | ||
| argument :signed_transaction, String, | ||
| required: true, | ||
| description: 'Signed transaction in HEX format' | ||
|
|
||
| field :watched_transaction, Types::WatchedTransaction::WatchedTransactionType, | ||
| null: true, | ||
| description: 'Newly created transaction' | ||
| field :errors, [UserErrorType], | ||
| null: false, | ||
| description: <<~EOS | ||
| Mutation errors | ||
|
|
||
| Operation Errors: | ||
| - Invalid transaction object | ||
| EOS | ||
|
|
||
| def resolve(transaction_hash:, transaction_object:, signed_transaction:) | ||
| key = :watched_transaction | ||
|
|
||
| attrs = { | ||
| txhash: transaction_hash, | ||
| transaction_object: transaction_object, | ||
| signed_transaction: signed_transaction | ||
| } | ||
|
|
||
| result, tx_or_errors = WatchingTransaction.watch( | ||
| context.fetch(:current_user), | ||
| attrs | ||
| ) | ||
|
|
||
| case result | ||
| when :invalid_data | ||
| model_errors(key, tx_or_errors) | ||
| when :ok | ||
| model_result(key, tx_or_errors) | ||
| end | ||
| end | ||
|
|
||
| def self.authorized?(object, context) | ||
| super && context.fetch(:current_user, nil) | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or 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,23 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module Resolvers | ||
| class WatchedTransactionResolver < Resolvers::Base | ||
bshevchenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| type Types::WatchedTransaction::WatchedTransactionType, null: true | ||
|
|
||
| argument :txhash, String, | ||
| required: true, | ||
| description: 'Find the last watched transaction in the group with that txhash' | ||
|
|
||
| def resolve(txhash:) | ||
| unless (tx = WatchingTransaction.find_by(txhash: txhash)) | ||
| return nil | ||
| end | ||
|
|
||
| WatchingTransaction.where(group_id: tx.group_id).order('created_at ASC').last | ||
| end | ||
|
|
||
| def self.authorized?(object, context) | ||
| super && context.fetch(:current_user, nil) | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.