Skip to content

Commit

Permalink
add reduce TX
Browse files Browse the repository at this point in the history
  • Loading branch information
SepehrGanji committed Mar 25, 2024
1 parent 4d355e9 commit fff8056
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/graphql/input-types/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,15 @@ export class SignedTransactionInput {
@Field({ nullable: true })
size?: number;
}

@InputType("ReduceTransaction")
export class ReduceTransactionInput {
@Field(() => String)
unsignedTransaction!: string;

@Field(() => [String])
inputBoxes!: string[];

@Field(() => [String])
dataInputBoxes!: string[];
}
38 changes: 37 additions & 1 deletion src/graphql/resolvers/transaction-resolver.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import { GraphQLResolveInfo } from "graphql";
import { Args, ArgsType, Ctx, Field, Info, Int, Query, Resolver } from "type-graphql";
import {
Arg,
Args,
ArgsType,
Ctx,
Field,
Info,
Int,
Mutation,
Query,
Resolver
} from "type-graphql";
import { Transaction } from "../objects/transaction";
import { removeUndefined } from "../../utils";
import { GraphQLContext } from "../context-type";
import { PaginationArguments } from "./pagination-arguments";
import { ArrayMaxSize } from "class-validator";
import { ReduceTransactionInput } from "../input-types";
import * as wasm from "ergo-lib-wasm-nodejs";
import { nodeService } from "../../services";

@ArgsType()
class TransactionArguments {
Expand Down Expand Up @@ -72,4 +86,26 @@ export class TransactionResolver {
take
});
}

@Mutation(() => String)
async reduceTransaction(@Arg("transaction") transaction: ReduceTransactionInput) {
try {
const tx = wasm.UnsignedTransaction.from_json(transaction.unsignedTransaction);
const ergoBoxes = wasm.ErgoBoxes.from_boxes_json(transaction.inputBoxes);
const dataInputBoxes = wasm.ErgoBoxes.from_boxes_json(transaction.dataInputBoxes);
const ctx = await nodeService.getStateContext();

const reducedTx = wasm.ReducedTransaction.from_unsigned_tx(
tx,
ergoBoxes,
dataInputBoxes,
ctx
);

return reducedTx.sigma_serialize_bytes().toString();
} catch (e: any) {

Check warning on line 106 in src/graphql/resolvers/transaction-resolver.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
console.error(e);
throw new Error(`Failed to reduce transaction! ${e.message}`);
}
}
}
7 changes: 7 additions & 0 deletions src/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ type Mempool {

type Mutation {
checkTransaction(signedTransaction: SignedTransaction!): String!
reduceTransaction(transaction: ReduceTransaction!): String!
submitTransaction(signedTransaction: SignedTransaction!): String!
}

Expand All @@ -235,6 +236,12 @@ type Query {
transactions(address: String, addresses: [String!], headerId: String, inclusionHeight: Int, maxHeight: Int, minHeight: Int, skip: Int = 0, take: Int = 50, transactionId: String, transactionIds: [String!]): [Transaction!]!
}

input ReduceTransaction {
dataInputBoxes: [String!]!
inputBoxes: [String!]!
unsignedTransaction: String!
}

input Registers {
R4: String
R5: String
Expand Down

0 comments on commit fff8056

Please sign in to comment.