Skip to content

Commit

Permalink
DigixGlobal#70 resend transaction mutation test + fixed watched trans…
Browse files Browse the repository at this point in the history
…action resolver
  • Loading branch information
bshevchenko committed Sep 2, 2019
1 parent 38bdab3 commit bccfa76
Show file tree
Hide file tree
Showing 5 changed files with 299 additions and 66 deletions.
11 changes: 5 additions & 6 deletions app/graphql/mutations/resend_transaction_mutation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,15 @@ class ResendTransactionMutation < Types::Base::BaseMutation
def resolve(id:, transaction_object:, signed_transaction:)
key = :watched_transaction

unless (old = WatchingTransaction.find(id))
return form_error(key, 'transaction_object', 'Previous transaction not found')
end

old = WatchingTransaction.find(id)
old_data = JSON.parse(old.transaction_object)
data = JSON.parse(transaction_object)

unless old_data.nonce == data.nonce
unless old_data['nonce'] == data['nonce']
return form_error(key, 'id', 'Nonce is not the same as the previous')
end

result, tx_or_errors = WatchingTransaction.resend(
result, tx_or_errors = WatchingTransaction.watch(
context.fetch(:current_user),
transaction_object,
signed_transaction,
Expand All @@ -54,6 +51,8 @@ def resolve(id:, transaction_object:, signed_transaction:)
when :ok
model_result(key, tx_or_errors)
end
rescue ActiveRecord::RecordNotFound
return form_error(key, 'transaction_object', 'Previous transaction not found')
end

def self.authorized?(object, context)
Expand Down
3 changes: 2 additions & 1 deletion app/graphql/resolvers/watched_transaction_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class WatchedTransactionResolver < Resolvers::Base
description: 'Find the last watched transaction in the group with that txhash'

def resolve(txhash:)
WatchingTransaction.find_by(txhash: txhash) # TODO or get group_id from this one and find latter by it?
tx = WatchingTransaction.find_by(txhash: txhash)
WatchingTransaction.find_by(group_id: tx.group_id).last
end

def self.authorized?(object, context)
Expand Down
184 changes: 129 additions & 55 deletions app/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -467,26 +467,6 @@ type CommentUpdatedPayload {
comment: UpdatedComment!
}

"""
Country for KYC Registration
"""
type WatchedTransaction {
"""
UUID of the watched transaction
"""
id: ID!

"""
Signer of the transaction
"""
user: User!

"""
The JSONified transaction data object
"""
transactionObject: String
}

"""
Country for KYC Registration
"""
Expand Down Expand Up @@ -1148,18 +1128,18 @@ type Mutation {
"""
postComment(input: PostCommentMutationInput!): PostCommentMutationPayload

"""
Given a transaction, save it to the database to be resent.
"""
watchTransaction(input: WatchTransactionMutationInput!): WatchTransactionMutationPayload

"""
As a KYC officer, reject a pending KYC with a reason.
Role: KYC Officer
"""
rejectKyc(input: RejectKycMutationInput!): RejectKycMutationPayload

"""
Given an old transaction, resend it with new parameters or gas prices
"""
resendTransaction(input: ResendTransactionMutationInput!): ResendTransactionMutationPayload

"""
As the current user, submit a KYC to access more features of the app.
Expand Down Expand Up @@ -1196,6 +1176,11 @@ type Mutation {
Can only unpost a comment you posted.
"""
unpostComment(input: UnpostCommentMutationInput!): UnpostCommentMutationPayload

"""
Given a transaction, save it to the database to be resent
"""
watchTransaction(input: WatchTransactionMutationInput!): WatchTransactionMutationPayload
}

"""
Expand Down Expand Up @@ -1280,36 +1265,6 @@ type PostCommentMutationPayload {
errors: [UserError!]!
}

"""
Autogenerated input type of WatchTransactionMutation
"""
input WatchTransactionMutationInput {
"""
The JSONified transaction data object
"""
transactionObject: String!

"""
Signed transaction in HEX format
"""
signedTransaction: String!
}

"""
Autogenerated return type of PostCommentMutation
"""
type WatchTransactionMutationPayload {
"""
Newly created transaction
"""
watchedTransaction: WatchedTransaction

"""
Mutation errors
"""
errors: [UserError!]!
}

"""
DAO proposals/projects to be voted and funded for
"""
Expand Down Expand Up @@ -1642,6 +1597,16 @@ type Query {
"""
id: String!
): AuthorizedUser

"""
Given a transaction txhash, find the last watched transaction in the group with that txhash.
"""
watchedTransaction(
"""
Find the last watched transaction in the group with that txhash
"""
txhash: String!
): WatchedTransaction
}

"""
Expand Down Expand Up @@ -1707,6 +1672,55 @@ A rejection rason represented by a string that comes form `RejectionReason.value
"""
scalar RejectionReasonValue

"""
Autogenerated input type of ResendTransactionMutation
"""
input ResendTransactionMutationInput {
"""
A unique identifier for the client performing the mutation.
"""
clientMutationId: String

"""
ID of the transaction to be resent
"""
id: String!

"""
Signed transaction in HEX format
"""
signedTransaction: String!

"""
The JSONified transaction data object
"""
transactionObject: String!
}

"""
Autogenerated return type of ResendTransactionMutation
"""
type ResendTransactionMutationPayload {
"""
A unique identifier for the client performing the mutation.
"""
clientMutationId: String

"""
Mutation errors
Operation Errors:
- Previous transaction not found
- Nonce is not the same as the previous
"""
errors: [UserError!]!

"""
Newly created transaction
"""
watchedTransaction: WatchedTransaction
}

"""
Customer residence proof for KYC submission
"""
Expand Down Expand Up @@ -2469,3 +2483,63 @@ enum VotingStageEnum {
"""
REVEAL
}

"""
Autogenerated input type of WatchTransactionMutation
"""
input WatchTransactionMutationInput {
"""
A unique identifier for the client performing the mutation.
"""
clientMutationId: String

"""
Signed transaction in HEX format
"""
signedTransaction: String!

"""
The JSONified transaction data object
"""
transactionObject: String!
}

"""
Autogenerated return type of WatchTransactionMutation
"""
type WatchTransactionMutationPayload {
"""
A unique identifier for the client performing the mutation.
"""
clientMutationId: String

"""
Mutation errors
"""
errors: [UserError!]!

"""
Newly created transaction
"""
watchedTransaction: WatchedTransaction
}

"""
Transactions that are being watched in the blockchain
"""
type WatchedTransaction {
"""
UUID of the watched transaction
"""
id: ID!

"""
The JSONified transaction data object
"""
transactionObject: String!

"""
Signer of the transaction
"""
user: User!
}

0 comments on commit bccfa76

Please sign in to comment.