Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
goga-m committed Nov 5, 2024
1 parent 9467818 commit c16c698
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 55 deletions.
142 changes: 87 additions & 55 deletions packages/ark/source/client.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,57 @@ import dotify from "node-dotify";
import { Enums } from "./crypto/index.js";
import { Request } from "./request.js";

const transactionTypeByName = (type: string) => ({
delegateRegistration: {
type: Enums.TransactionType.DelegateRegistration,
typeGroup: Enums.TransactionTypeGroup.Core,
},
delegateResignation: {
type: Enums.TransactionType.DelegateResignation,
typeGroup: Enums.TransactionTypeGroup.Core,
},
htlcClaim: {
type: Enums.TransactionType.HtlcClaim,
typeGroup: Enums.TransactionTypeGroup.Core,
},
htlcLock: {
type: Enums.TransactionType.HtlcLock,
typeGroup: Enums.TransactionTypeGroup.Core,
},
htlcRefund: {
type: Enums.TransactionType.HtlcRefund,
typeGroup: Enums.TransactionTypeGroup.Core,
},
ipfs: {
type: Enums.TransactionType.Ipfs,
typeGroup: Enums.TransactionTypeGroup.Core,
},
magistrate: {
typeGroup: 2,
},
multiPayment: {
type: Enums.TransactionType.MultiPayment,
typeGroup: Enums.TransactionTypeGroup.Core,
},
multiSignature: {
type: Enums.TransactionType.MultiSignature,
typeGroup: Enums.TransactionTypeGroup.Core,
},
secondSignature: {
type: Enums.TransactionType.SecondSignature,
typeGroup: Enums.TransactionTypeGroup.Core,
},
transfer: {
type: Enums.TransactionType.Transfer,
typeGroup: Enums.TransactionTypeGroup.Core,
},
vote: {
type: Enums.TransactionType.Vote,
typeGroup: Enums.TransactionTypeGroup.Core,
},
// @ts-ignore
}[type])

export class ClientService extends Services.AbstractClientService {
readonly #request: Request;

Expand Down Expand Up @@ -92,11 +143,11 @@ export class ClientService extends Services.AbstractClientService {
used: hasVoted ? 1 : 0,
votes: hasVoted
? [
{
amount: 0,
id: vote,
},
]
{
amount: 0,
id: vote,
},
]
: [],
};
}
Expand Down Expand Up @@ -227,56 +278,7 @@ export class ClientService extends Services.AbstractClientService {

// @ts-ignore
if (body.type) {
const { type, typeGroup } = {
delegateRegistration: {
type: Enums.TransactionType.DelegateRegistration,
typeGroup: Enums.TransactionTypeGroup.Core,
},
delegateResignation: {
type: Enums.TransactionType.DelegateResignation,
typeGroup: Enums.TransactionTypeGroup.Core,
},
htlcClaim: {
type: Enums.TransactionType.HtlcClaim,
typeGroup: Enums.TransactionTypeGroup.Core,
},
htlcLock: {
type: Enums.TransactionType.HtlcLock,
typeGroup: Enums.TransactionTypeGroup.Core,
},
htlcRefund: {
type: Enums.TransactionType.HtlcRefund,
typeGroup: Enums.TransactionTypeGroup.Core,
},
ipfs: {
type: Enums.TransactionType.Ipfs,
typeGroup: Enums.TransactionTypeGroup.Core,
},
magistrate: {
typeGroup: 2,
},
multiPayment: {
type: Enums.TransactionType.MultiPayment,
typeGroup: Enums.TransactionTypeGroup.Core,
},
multiSignature: {
type: Enums.TransactionType.MultiSignature,
typeGroup: Enums.TransactionTypeGroup.Core,
},
secondSignature: {
type: Enums.TransactionType.SecondSignature,
typeGroup: Enums.TransactionTypeGroup.Core,
},
transfer: {
type: Enums.TransactionType.Transfer,
typeGroup: Enums.TransactionTypeGroup.Core,
},
vote: {
type: Enums.TransactionType.Vote,
typeGroup: Enums.TransactionTypeGroup.Core,
},
// @ts-ignore
}[body.type];
const { type, typeGroup } = transactionTypeByName(body.type)

if (type !== undefined) {
if (isLegacy) {
Expand All @@ -300,6 +302,36 @@ export class ClientService extends Services.AbstractClientService {
}
}

if (Array.isArray(body.types)) {
const { typeGroup } = transactionTypeByName(body.types.at(0));

const types = body.types.map((transactionType: string) => {
const { type } = transactionTypeByName(transactionType);
return type
}).join(",")

if (types !== undefined) {
if (isLegacy) {
result.body!.type = types;
} else {
result.searchParams.type = types;
}
}

if (typeGroup !== undefined) {
if (isLegacy) {
result.body!.typeGroup = typeGroup;
} else {
result.searchParams.typeGroup = typeGroup;
}
}

if (!isLegacy) {
// @ts-ignore
delete body.types;
}
}

if (body.timestamp) {
const normalizeTimestamps = (timestamp: Services.RangeCriteria) => {
const epoch: string = this.configRepository.get<string>("network.constants.epoch");
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/source/client.contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export interface ClientTransactionsInput extends ClientPagination {
timestamp?: RangeCriteria;
// Transaction Types
type?: TransactionType;
types?: TransactionType[];
}

export interface ClientWalletsInput extends ClientPagination {
Expand Down

0 comments on commit c16c698

Please sign in to comment.