Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: integrate hedera family #128

Merged
merged 1 commit into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ lib/
lib-es/

# eslint cache
.eslintcache
.eslintcache

# ide
.idea
1 change: 1 addition & 0 deletions packages/core/src/families/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const FAMILIES = [
"cosmos",
"ripple",
"cosmos",
"hedera",
"tezos",
"polkadot",
"stellar",
Expand Down
30 changes: 30 additions & 0 deletions packages/core/src/families/hedera/serializer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import BigNumber from "bignumber.js";
import type { HederaTransaction, RawHederaTransaction } from "./types";

export function serializeHederaTransaction({
amount,
family,
memo = undefined,
recipient,
}: HederaTransaction): RawHederaTransaction {
return {
amount: amount.toString(),
family,
memo,
recipient,
};
}

export function deserializeHederaTransaction({
amount,
family,
memo = undefined,
recipient,
}: RawHederaTransaction): HederaTransaction {
return {
amount: new BigNumber(amount),
family,
memo,
recipient,
};
}
10 changes: 10 additions & 0 deletions packages/core/src/families/hedera/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { z } from "zod";
import type { TransactionCommon } from "../index";
import type { schemaRawHederaTransaction } from "./validation";

export interface HederaTransaction extends TransactionCommon {
readonly family: RawHederaTransaction["family"];
memo?: string;
}

export type RawHederaTransaction = z.infer<typeof schemaRawHederaTransaction>;
7 changes: 7 additions & 0 deletions packages/core/src/families/hedera/validation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { z } from "zod";
import { schemaFamilies, schemaTransactionCommon } from "../common";

export const schemaRawHederaTransaction = schemaTransactionCommon.extend({
family: z.literal(schemaFamilies.enum.hedera),
memo: z.string().max(100).optional(),
});
1 change: 1 addition & 0 deletions packages/core/src/families/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from "./bitcoin/types";
export * from "./cosmos/types";
export * from "./crypto_org/types";
export * from "./ethereum/types";
export * from "./hedera/types";
export * from "./polkadot/types";
export * from "./ripple/types";
export * from "./stellar/types";
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/families/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import {
deserializeEthereumTransaction,
serializeEthereumTransaction,
} from "./ethereum/serializer";
import {
deserializeHederaTransaction,
serializeHederaTransaction,
} from "./hedera/serializer";
import {
deserializePolkadotTransaction,
serializePolkadotTransaction,
Expand Down Expand Up @@ -62,6 +66,8 @@ export function serializeTransaction(transaction: Transaction): RawTransaction {
return serializeRippleTransaction(transaction);
case "cosmos":
return serializeCosmosTransaction(transaction);
case "hedera":
return serializeHederaTransaction(transaction);
case "tezos":
return serializeTezosTransaction(transaction);
case "polkadot":
Expand Down Expand Up @@ -101,6 +107,8 @@ export function deserializeTransaction(
return deserializeRippleTransaction(rawTransaction);
case "cosmos":
return deserializeCosmosTransaction(rawTransaction);
case "hedera":
return deserializeHederaTransaction(rawTransaction);
case "tezos":
return deserializeTezosTransaction(rawTransaction);
case "polkadot":
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/families/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { schemaFamilies } from "./common";
import type { CosmosTransaction } from "./cosmos/types";
import type { CryptoOrgTransaction } from "./crypto_org/types";
import type { EthereumTransaction } from "./ethereum/types";
import type { HederaTransaction } from "./hedera/types";
import type { PolkadotTransaction } from "./polkadot/types";
import type { RippleTransaction } from "./ripple/types";
import type { StellarTransaction } from "./stellar/types";
Expand Down Expand Up @@ -58,6 +59,7 @@ export type Transaction =
| BitcoinTransaction
| AlgorandTransaction
| CryptoOrgTransaction
| HederaTransaction
| RippleTransaction
| CosmosTransaction
| TezosTransaction
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/families/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import { schemaRawRippleTransaction } from "./ripple/validation";
import { schemaRawStellarTransaction } from "./stellar/validation";
import { schemaRawTezosTransaction } from "./tezos/validation";
import { schemaRawTronTransaction } from "./tron/validation";
import { schemaRawHederaTransaction } from "./hedera/validation";

export const schemaRawTransaction = z.discriminatedUnion("family", [
schemaRawAlgorandTransaction,
schemaRawBitcoinTransaction,
schemaRawCosmosTransaction,
schemaRawCryptoOrgTransaction,
schemaRawEthereumTransaction,
schemaRawHederaTransaction,
schemaRawPolkadotTransaction,
schemaRawRippleTransaction,
schemaRawStellarTransaction,
Expand Down
59 changes: 35 additions & 24 deletions website/docs/reference/api/client/index.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For example in BTC, a tx with an 'amount' field of 1 will correspond to a tx cor

#### Defined in

packages/core/lib/families/types.d.ts:37
packages/core/lib/families/types.d.ts:38

___

Expand Down Expand Up @@ -101,4 +101,4 @@ The address of the transaction's recipient

#### Defined in

packages/core/lib/families/types.d.ts:41
packages/core/lib/families/types.d.ts:42
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For example in BTC, a tx with an 'amount' field of 1 will correspond to a tx cor

#### Defined in

packages/core/lib/families/types.d.ts:37
packages/core/lib/families/types.d.ts:38

___

Expand Down Expand Up @@ -81,4 +81,4 @@ The address of the transaction's recipient

#### Defined in

packages/core/lib/families/types.d.ts:41
packages/core/lib/families/types.d.ts:42
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For example in BTC, a tx with an 'amount' field of 1 will correspond to a tx cor

#### Defined in

packages/core/lib/families/types.d.ts:37
packages/core/lib/families/types.d.ts:38

___

Expand Down Expand Up @@ -101,4 +101,4 @@ The address of the transaction's recipient

#### Defined in

packages/core/lib/families/types.d.ts:41
packages/core/lib/families/types.d.ts:42
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For example in BTC, a tx with an 'amount' field of 1 will correspond to a tx cor

#### Defined in

packages/core/lib/families/types.d.ts:37
packages/core/lib/families/types.d.ts:38

___

Expand Down Expand Up @@ -81,4 +81,4 @@ The address of the transaction's recipient

#### Defined in

packages/core/lib/families/types.d.ts:41
packages/core/lib/families/types.d.ts:42
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For example in BTC, a tx with an 'amount' field of 1 will correspond to a tx cor

#### Defined in

packages/core/lib/families/types.d.ts:37
packages/core/lib/families/types.d.ts:38

___

Expand Down Expand Up @@ -101,4 +101,4 @@ The address of the transaction's recipient

#### Defined in

packages/core/lib/families/types.d.ts:41
packages/core/lib/families/types.d.ts:42
74 changes: 74 additions & 0 deletions website/docs/reference/api/client/interfaces/HederaTransaction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
id: "HederaTransaction"
title: "Interface: HederaTransaction"
sidebar_label: "HederaTransaction"
sidebar_position: 0
custom_edit_url: null
---

Common fields for all cryptocurrency transactions

## Hierarchy

- [`TransactionCommon`](TransactionCommon.md)

↳ **`HederaTransaction`**

## Properties

### amount

• **amount**: `BigNumber`

The amount of token to send in the transaction, denoted in the smallest cryptocurrency's magnitude
For example in BTC, a tx with an 'amount' field of 1 will correspond to a tx corresponding to 0.00000001 BTC

#### Inherited from

[TransactionCommon](TransactionCommon.md).[amount](TransactionCommon.md#amount)

#### Defined in

packages/core/lib/families/types.d.ts:38

___

### family

• `Readonly` **family**: ``"hedera"``

The family of the transaction

#### Overrides

[TransactionCommon](TransactionCommon.md).[family](TransactionCommon.md#family)

#### Defined in

packages/core/lib/families/hedera/types.d.ts:5

___

### memo

• `Optional` **memo**: `string`

#### Defined in

packages/core/lib/families/hedera/types.d.ts:6

___

### recipient

• **recipient**: `string`

The address of the transaction's recipient

#### Inherited from

[TransactionCommon](TransactionCommon.md).[recipient](TransactionCommon.md#recipient)

#### Defined in

packages/core/lib/families/types.d.ts:42
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For example in BTC, a tx with an 'amount' field of 1 will correspond to a tx cor

#### Defined in

packages/core/lib/families/types.d.ts:37
packages/core/lib/families/types.d.ts:38

___

Expand Down Expand Up @@ -91,4 +91,4 @@ The address of the transaction's recipient

#### Defined in

packages/core/lib/families/types.d.ts:41
packages/core/lib/families/types.d.ts:42
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For example in BTC, a tx with an 'amount' field of 1 will correspond to a tx cor

#### Defined in

packages/core/lib/families/types.d.ts:37
packages/core/lib/families/types.d.ts:38

___

Expand Down Expand Up @@ -71,7 +71,7 @@ The address of the transaction's recipient

#### Defined in

packages/core/lib/families/types.d.ts:41
packages/core/lib/families/types.d.ts:42

___

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For example in BTC, a tx with an 'amount' field of 1 will correspond to a tx cor

#### Defined in

packages/core/lib/families/types.d.ts:37
packages/core/lib/families/types.d.ts:38

___

Expand Down Expand Up @@ -91,4 +91,4 @@ The address of the transaction's recipient

#### Defined in

packages/core/lib/families/types.d.ts:41
packages/core/lib/families/types.d.ts:42
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For example in BTC, a tx with an 'amount' field of 1 will correspond to a tx cor

#### Defined in

packages/core/lib/families/types.d.ts:37
packages/core/lib/families/types.d.ts:38

___

Expand Down Expand Up @@ -91,4 +91,4 @@ The address of the transaction's recipient

#### Defined in

packages/core/lib/families/types.d.ts:41
packages/core/lib/families/types.d.ts:42
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Common fields for all cryptocurrency transactions

↳ [`EthereumTransaction`](EthereumTransaction.md)

↳ [`HederaTransaction`](HederaTransaction.md)

↳ [`PolkadotTransaction`](PolkadotTransaction.md)

↳ [`RippleTransaction`](RippleTransaction.md)
Expand All @@ -43,19 +45,19 @@ For example in BTC, a tx with an 'amount' field of 1 will correspond to a tx cor

#### Defined in

packages/core/lib/families/types.d.ts:37
packages/core/lib/families/types.d.ts:38

___

### family

• **family**: ``"bitcoin"`` \| ``"ethereum"`` \| ``"algorand"`` \| ``"crypto_org"`` \| ``"ripple"`` \| ``"cosmos"`` \| ``"tezos"`` \| ``"polkadot"`` \| ``"stellar"`` \| ``"tron"``
• **family**: ``"bitcoin"`` \| ``"ethereum"`` \| ``"algorand"`` \| ``"crypto_org"`` \| ``"ripple"`` \| ``"cosmos"`` \| ``"hedera"`` \| ``"tezos"`` \| ``"polkadot"`` \| ``"stellar"`` \| ``"tron"``

The family of the transaction

#### Defined in

packages/core/lib/families/types.d.ts:32
packages/core/lib/families/types.d.ts:33

___

Expand All @@ -67,4 +69,4 @@ The address of the transaction's recipient

#### Defined in

packages/core/lib/families/types.d.ts:41
packages/core/lib/families/types.d.ts:42