mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
update resolver result
This commit is contained in:
parent
c7dbf9ac7f
commit
ddbec0ae3b
@ -3,11 +3,13 @@ import { TransactionError } from './TransactionError'
|
||||
|
||||
@ObjectType()
|
||||
export class TransactionResult {
|
||||
constructor(content: TransactionError | Buffer) {
|
||||
constructor(content: TransactionError | Buffer | string) {
|
||||
if (content instanceof TransactionError) {
|
||||
this.error = content
|
||||
} else if (content instanceof Buffer) {
|
||||
this.messageId = content.toString('hex')
|
||||
} else if (typeof content === 'string') {
|
||||
this.messageId = content
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -7,6 +7,8 @@ import { create as createGradidoTransaction } from '@controller/GradidoTransacti
|
||||
|
||||
import { sendMessage as iotaSendMessage } from '@/client/IotaClient'
|
||||
import { GradidoTransaction } from '@/proto/3_3/GradidoTransaction'
|
||||
import { TransactionResult } from '../model/TransactionResult'
|
||||
import { TransactionError } from '../model/TransactionError'
|
||||
|
||||
@Resolver()
|
||||
export class TransactionResolver {
|
||||
@ -25,11 +27,18 @@ export class TransactionResolver {
|
||||
async sendTransaction(
|
||||
@Arg('data')
|
||||
transaction: TransactionDraft,
|
||||
): Promise<string> {
|
||||
const body = createTransactionBody(transaction)
|
||||
const message = createGradidoTransaction(body)
|
||||
const messageBuffer = GradidoTransaction.encode(message).finish()
|
||||
const resultMessage = await iotaSendMessage(messageBuffer)
|
||||
return resultMessage.messageId
|
||||
): Promise<TransactionResult> {
|
||||
try {
|
||||
const body = createTransactionBody(transaction)
|
||||
const message = createGradidoTransaction(body)
|
||||
const messageBuffer = GradidoTransaction.encode(message).finish()
|
||||
const resultMessage = await iotaSendMessage(messageBuffer)
|
||||
return new TransactionResult(resultMessage.messageId)
|
||||
} catch (error) {
|
||||
if (error instanceof TransactionError) {
|
||||
return new TransactionResult(error)
|
||||
}
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user