|
1 | | -import type { Transaction as ThorTransaction } from "thor-devkit"; |
2 | 1 | import type { z } from "zod"; |
3 | 2 | import type { TransactionCommon } from "../index"; |
4 | 3 | import type { schemaRawVechainTransaction } from "./validation"; |
5 | 4 |
|
6 | 5 | export type VechainTransaction = TransactionCommon & { |
7 | 6 | readonly family: RawVechainTransaction["family"]; |
8 | 7 | estimatedFees: string; |
9 | | - body: ThorTransaction.Body; |
| 8 | + body: TransactionBody; |
10 | 9 | }; |
11 | 10 |
|
12 | 11 | export type RawVechainTransaction = z.infer<typeof schemaRawVechainTransaction>; |
| 12 | + |
| 13 | +// Copied vechain-sdk-js |
| 14 | +// https://github.com/vechain/vechain-sdk-js/blob/main/packages/core/src/transaction/TransactionClause.d.ts |
| 15 | +type TransactionClause = { |
| 16 | + /** |
| 17 | + * Destination address where: |
| 18 | + * * transfer token to or |
| 19 | + * * invoke contract method on. |
| 20 | + * |
| 21 | + * @note Set null destination to deploy a contract. |
| 22 | + */ |
| 23 | + to: string | null; |
| 24 | + |
| 25 | + /** |
| 26 | + * Amount of token to transfer to the destination |
| 27 | + */ |
| 28 | + value: string | number; |
| 29 | + |
| 30 | + /** |
| 31 | + * Input data for contract method invocation or deployment |
| 32 | + */ |
| 33 | + data: string; |
| 34 | + |
| 35 | + /** |
| 36 | + * Optional comment for the clause, helpful for displaying what the clause is doing. |
| 37 | + */ |
| 38 | + comment?: string; |
| 39 | + |
| 40 | + /** |
| 41 | + * Optional ABI for the contract method invocation. |
| 42 | + */ |
| 43 | + abi?: string; |
| 44 | +}; |
| 45 | + |
| 46 | +// Copied vechain-sdk-js |
| 47 | +// https://github.com/vechain/vechain-sdk-js/blob/main/packages/core/src/transaction/TransactionBody.d.ts |
| 48 | +type TransactionBody = { |
| 49 | + /** |
| 50 | + * Last byte of genesis block ID |
| 51 | + */ |
| 52 | + chainTag: number; |
| 53 | + |
| 54 | + /** |
| 55 | + * 8 bytes prefix of some block's ID |
| 56 | + */ |
| 57 | + blockRef: string; |
| 58 | + |
| 59 | + /** |
| 60 | + * Constraint of time bucket |
| 61 | + */ |
| 62 | + expiration: number; |
| 63 | + |
| 64 | + /** |
| 65 | + * Array of clauses |
| 66 | + */ |
| 67 | + clauses: TransactionClause[]; |
| 68 | + |
| 69 | + /** |
| 70 | + * Coefficient applied to base gas price [0,255] |
| 71 | + */ |
| 72 | + gasPriceCoef?: number; |
| 73 | + |
| 74 | + /** |
| 75 | + * Max gas provided for execution |
| 76 | + */ |
| 77 | + gas: string | number; |
| 78 | + |
| 79 | + /** |
| 80 | + * ID of another tx that is depended |
| 81 | + */ |
| 82 | + dependsOn: string | null; |
| 83 | + |
| 84 | + /** |
| 85 | + * Nonce value for various purposes. |
| 86 | + * Basic is to prevent replay attack by make transaction unique. |
| 87 | + * Every transaction with same chainTag, blockRef, ... must have different nonce. |
| 88 | + */ |
| 89 | + nonce: string | number; |
| 90 | + |
| 91 | + /** |
| 92 | + * The maximum fee per gas for the transaction. |
| 93 | + */ |
| 94 | + maxFeePerGas?: string | number; |
| 95 | + |
| 96 | + /** |
| 97 | + * The maximum priority fee per gas for the transaction. |
| 98 | + */ |
| 99 | + maxPriorityFeePerGas?: string | number; |
| 100 | + |
| 101 | + /** |
| 102 | + * A reserved field intended for features use. |
| 103 | + * |
| 104 | + * In standard EVM transactions, this reserved field typically is not present. |
| 105 | + * However, it's been designed to cater to VIP-191, which deals with fee delegation. |
| 106 | + * |
| 107 | + * If the `features` within the `reserved` field is set as `1111...111`, it indicates that the transaction has been delegated. |
| 108 | + * The method to check if the transaction is delegated is: |
| 109 | + * |
| 110 | + * ```typescript |
| 111 | + * reserved.features & 1 === 1 |
| 112 | + * ``` |
| 113 | + * |
| 114 | + * @example |
| 115 | + * |
| 116 | + * 1. |
| 117 | + * ```typescript |
| 118 | + * feature = 111101; |
| 119 | + * isDelegated = (111101 & 111111) === 111101; // false (not delegated) |
| 120 | + * ``` |
| 121 | + * |
| 122 | + * 2. |
| 123 | + * ```typescript |
| 124 | + * feature = 111111; |
| 125 | + * isDelegated = (111111 & 111111) === 111111; // true (delegated) |
| 126 | + * ``` |
| 127 | + * |
| 128 | + * @remarks |
| 129 | + * For more information on the subject, refer to {@link https://github.com/vechain/VIPs/blob/master/vips/VIP-191.md | VIP-191}. |
| 130 | + */ |
| 131 | + reserved?: { |
| 132 | + /** |
| 133 | + * Tx feature bits |
| 134 | + */ |
| 135 | + features?: number; |
| 136 | + /** |
| 137 | + * Unused |
| 138 | + */ |
| 139 | + unused?: Uint8Array[]; |
| 140 | + }; |
| 141 | +}; |
0 commit comments