-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add vechain family [LIVE-9715] (#332)
* feat: add vechain family * test: add serializers test for vechain
- Loading branch information
Showing
12 changed files
with
311 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@ledgerhq/wallet-api-core": minor | ||
--- | ||
|
||
feat: add vechain family |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import BigNumber from "bignumber.js"; | ||
import type { RawVechainTransaction, VechainTransaction } from "./types"; | ||
|
||
export const serializeVechainTransaction = ({ | ||
amount, | ||
recipient, | ||
family, | ||
estimatedFees, | ||
body, | ||
}: VechainTransaction): RawVechainTransaction => ({ | ||
amount: amount.toString(), | ||
recipient, | ||
family, | ||
estimatedFees, | ||
body, | ||
}); | ||
|
||
export const deserializeVechainTransaction = ({ | ||
amount, | ||
recipient, | ||
family, | ||
estimatedFees, | ||
body, | ||
}: RawVechainTransaction): VechainTransaction => ({ | ||
amount: new BigNumber(amount), | ||
recipient, | ||
family, | ||
estimatedFees, | ||
body, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Transaction as ThorTransaction } from "thor-devkit"; | ||
import type { z } from "zod"; | ||
import type { TransactionCommon } from "../index"; | ||
import type { schemaRawVechainTransaction } from "./validation"; | ||
|
||
export type VechainTransaction = TransactionCommon & { | ||
readonly family: RawVechainTransaction["family"]; | ||
estimatedFees: string; | ||
body: ThorTransaction.Body; | ||
}; | ||
|
||
export type RawVechainTransaction = z.infer<typeof schemaRawVechainTransaction>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { z } from "zod"; | ||
import { schemaFamilies, schemaTransactionCommon } from "../common"; | ||
|
||
// Generated from VeChain Thor Transaction types | ||
export const schemaThorTransactionClause = z.object({ | ||
to: z.string().nullable(), | ||
value: z.union([z.string(), z.number()]), | ||
data: z.string(), | ||
}); | ||
|
||
// Generated from VeChain Thor Transaction types | ||
// with Buffer type removed for `reserved.unused` | ||
export const schemaThorTransactionBody = z.object({ | ||
chainTag: z.number(), | ||
blockRef: z.string(), | ||
expiration: z.number(), | ||
clauses: z.array(schemaThorTransactionClause), | ||
gasPriceCoef: z.number(), | ||
gas: z.union([z.string(), z.number()]), | ||
dependsOn: z.string().nullable(), | ||
nonce: z.union([z.string(), z.number()]), | ||
reserved: z | ||
.object({ | ||
features: z.number().optional(), | ||
unused: z.array(z.any()).optional(), | ||
}) | ||
.optional(), | ||
}); | ||
|
||
export const schemaRawVechainTransaction = schemaTransactionCommon.extend({ | ||
family: z.literal(schemaFamilies.enum.vechain), | ||
estimatedFees: z.string(), | ||
body: schemaThorTransactionBody, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.