-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d44bb6
commit 0b61e36
Showing
20 changed files
with
1,106 additions
and
204 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
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 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 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 | ||
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 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.