Skip to content

Commit

Permalink
handle empty token accounts in transaction.sign #2
Browse files Browse the repository at this point in the history
signandbroadcast handles tokencurrency

test account receive

remove local manifest test
  • Loading branch information
Wozacosta committed Jan 19, 2024
1 parent 23a81cd commit 4a2cc14
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 8 deletions.
4 changes: 1 addition & 3 deletions apps/wallet-api-tools/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
"apiVersion": "^2.0.0",
"manifestVersion": "1",
"branch": "debug",
"categories": [
"tools"
],
"categories": ["tools"],
"currencies": "*",
"content": {
"shortDescription": {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/spec/types/AccountReceive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { z } from "zod";

const schemaAccountReceiveParams = z.object({
accountId: z.string(),
tokenCurrency: z.string().optional(),
});

const schemaAccountReceiveResults = z.object({
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/spec/types/TransactionSign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const schemaTransactionSignParams = z.object({
rawTransaction: schemaRawTransaction,
options: schemaTransactionOptions.optional(),
meta: z.record(z.string(), z.unknown()).optional(),
tokenCurrency: z.string().optional(),
});

const schemaTransactionSignResults = z.object({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const schemaTransactionSignAndBroadcastParams = z.object({
rawTransaction: schemaRawTransaction,
options: schemaTransactionOptions.optional(),
meta: z.record(z.string(), z.unknown()).optional(),
tokenCurrency: z.string().optional(),
});

const schemaTransactionSignAndBroadcastResults = z.object({
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/internalHandlers/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const receive: RPCHandler<AccountReceive["result"]> = async (
handlers,
) => {
const safeParams = schemaAccountReceive.params.parse(req.params);
const { accountId } = safeParams;
const { accountId, tokenCurrency } = safeParams;

const accounts = await firstValueFrom(context.accounts$);

Expand All @@ -108,7 +108,7 @@ export const receive: RPCHandler<AccountReceive["result"]> = async (
throw new ServerError(createNotImplementedByWallet("account.receive"));
}

const result = await walletHandler({ account });
const result = await walletHandler({ account, tokenCurrency });

return {
address: result,
Expand Down
8 changes: 6 additions & 2 deletions packages/server/src/internalHandlers/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export const sign: RPCHandler<TransactionSign["result"]> = async (

const accounts = await firstValueFrom(context.accounts$);

const { accountId, rawTransaction, options, meta } = safeParams;
const { accountId, rawTransaction, options, meta, tokenCurrency } =
safeParams;

const account = accounts.find((acc) => acc.id === accountId);

Expand All @@ -36,6 +37,7 @@ export const sign: RPCHandler<TransactionSign["result"]> = async (

const signedTransaction = await walletHandler({
account,
tokenCurrency,
transaction: deserializeTransaction(rawTransaction),
options,
meta,
Expand All @@ -61,7 +63,8 @@ export const signAndBroadcast: RPCHandler<

const accounts = await firstValueFrom(context.accounts$);

const { accountId, rawTransaction, options, meta } = safeParams;
const { accountId, rawTransaction, options, meta, tokenCurrency } =
safeParams;

const account = accounts.find((acc) => acc.id === accountId);

Expand All @@ -71,6 +74,7 @@ export const signAndBroadcast: RPCHandler<

const transactionHash = await walletHandler({
account,
tokenCurrency,
transaction: deserializeTransaction(rawTransaction),
options,
meta,
Expand Down
8 changes: 7 additions & 1 deletion packages/server/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,29 @@ export type WalletHandlers = {
currencies$: Observable<Currency[]>;
accounts$: Observable<Account[]>;
}) => Promisable<Account>;
"account.receive": (params: { account: Account }) => Promisable<string>;
"account.receive": (params: {
account: Account;
tokenCurrency?: string;
}) => Promisable<string>;
"message.sign": (params: {
account: Account;
message: Buffer;
meta: Record<string, unknown> | undefined;
tokenCurrency?: string;
}) => Promisable<Buffer>;
"transaction.sign": (params: {
account: Account;
transaction: Transaction;
options?: TransactionSign["params"]["options"];
meta: Record<string, unknown> | undefined;
tokenCurrency?: string;
}) => Promisable<Buffer>;
"transaction.signAndBroadcast": (params: {
account: Account;
transaction: Transaction;
options?: TransactionSignAndBroadcast["params"]["options"];
meta: Record<string, unknown> | undefined;
tokenCurrency?: string;
}) => Promisable<string>;
"device.close": (params: DeviceClose["params"]) => Promisable<string>;
"device.exchange": (params: DeviceExchange["params"]) => Promisable<string>;
Expand Down

0 comments on commit 4a2cc14

Please sign in to comment.