-
Notifications
You must be signed in to change notification settings - Fork 0
[BTC] Tx crafting #60
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
Changes from 2 commits
041e420
6c1781d
ac24a9d
294e452
132abf0
e19dc5b
9b6ba0d
604312b
4db7c3f
260198c
82885d1
5cbb6bf
423f4a8
519e2cc
b7d714c
6819ac4
0f8f760
e66443c
334ff60
1b128db
b00e97e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| diff --git a/index.d.ts b/index.d.ts | ||
| new file mode 100644 | ||
| index 0000000..20cc98a | ||
| --- /dev/null | ||
| +++ b/index.d.ts | ||
| @@ -0,0 +1,25 @@ | ||
| +export interface UTXO { | ||
| + txid: string | Buffer; | ||
| + vout: number; | ||
| + value: number; | ||
| + nonWitnessUtxo?: Buffer; | ||
| + witnessUtxo?: { | ||
| + script: Buffer; | ||
| + value: number; | ||
| + }; | ||
| +} | ||
| +export interface Target { | ||
| + address?: string; | ||
| + value: number; | ||
| +} | ||
| +export interface SelectedUTXO { | ||
| + inputs?: UTXO[]; | ||
| + outputs?: Target[]; | ||
| + fee: number; | ||
| +} | ||
| + | ||
| +export default function coinSelect( | ||
| + utxos: UTXO[], | ||
| + outputs: Target[], | ||
| + feeRate: number | ||
| +): SelectedUTXO; | ||
| diff --git a/package.json b/package.json | ||
| index 6cdef00..337bf4f 100644 | ||
| --- a/package.json | ||
| +++ b/package.json | ||
| @@ -31,6 +31,7 @@ | ||
| "utils.js" | ||
| ], | ||
| "main": "index.js", | ||
| + "types": "index.d.ts", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/bitcoinjs/coinselect.git" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,27 @@ | ||
| import { UTXO } from "coinselect"; | ||
| import z from "zod"; | ||
|
|
||
| // Blockchair responses SUB-MODELS | ||
| const UtxosSchema = z.object({ | ||
| block_id: z.number(), | ||
| transaction_hash: z.string(), | ||
| index: z.number(), | ||
| value: z.number(), | ||
| address: z.string(), | ||
| }); | ||
| const UtxosSchema = z | ||
| .object({ | ||
| block_id: z.number(), | ||
| transaction_hash: z.string(), | ||
| index: z.number(), | ||
| value: z.number(), | ||
| address: z.string(), | ||
| }) | ||
| .transform((data) => { | ||
| return { | ||
| /** | ||
| * add fields for compatibility with coinselect @see {@link UTXO} | ||
| */ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (nitpicking)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just wanted to have the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Realised it could be done in one line 🤦 |
||
| txid: data.transaction_hash, | ||
| vout: data.index, | ||
| ...data, | ||
| }; | ||
| }); | ||
|
|
||
| export type UtxoWithMetadata = z.infer<typeof UtxosSchema>; | ||
|
|
||
| const AddressSchema = z.object({ | ||
| type: z.string(), | ||
|
|
@@ -69,17 +83,21 @@ export const requestContextSchema = z.object({ | |
| rows: z.number().optional(), | ||
| market_price_usd: z.number().optional(), | ||
| total_rows: z.number().optional(), | ||
| api: z.object({ | ||
| version: z.string(), | ||
| last_major_update: z.string().optional(), | ||
| next_major_update: z.string().optional(), | ||
| documentation: z.string().optional(), | ||
| notice: z.string().optional(), | ||
| }).optional(), | ||
| cache: z.object({ | ||
| live: z.boolean(), | ||
| until: z.string().optional(), | ||
| }).optional(), | ||
| api: z | ||
| .object({ | ||
| version: z.string(), | ||
| last_major_update: z.string().optional(), | ||
| next_major_update: z.string().optional(), | ||
| documentation: z.string().optional(), | ||
| notice: z.string().optional(), | ||
| }) | ||
| .optional(), | ||
| cache: z | ||
| .object({ | ||
| live: z.boolean(), | ||
| until: z.string().optional(), | ||
| }) | ||
| .optional(), | ||
| request_cost: z.number(), | ||
| }); | ||
|
|
||
|
|
@@ -185,7 +203,8 @@ export const requestContextSchema = z.object({ | |
| } | ||
| */ | ||
| export const XpubDashboardData = z.record( | ||
| z.string(), z.object({ | ||
| z.string(), | ||
| z.object({ | ||
| xpub: z.object({ | ||
| address_count: z.number(), | ||
| balance: z.number().pipe(z.coerce.bigint()), | ||
|
|
@@ -203,9 +222,12 @@ export const XpubDashboardData = z.record( | |
| transaction_count: z.number(), | ||
| }), | ||
| addresses: z.record( | ||
| z.string(), AddressSchema.and(z.object({ | ||
| path: z.string(), | ||
| })) | ||
| z.string(), | ||
| AddressSchema.and( | ||
| z.object({ | ||
| path: z.string(), | ||
| }) | ||
| ) | ||
| ), | ||
| transactions: z.array(z.string()), | ||
| utxo: UtxosSchema.array(), | ||
|
|
@@ -219,7 +241,7 @@ export const XpubDashboardResponse = z.object({ | |
| z.object({ | ||
| checked: z.array(z.string()), | ||
| }) | ||
| ) | ||
| ), | ||
| }); | ||
|
|
||
| export const AddressesDashboardResponse = z.object({ | ||
|
|
@@ -230,13 +252,13 @@ export const AddressesDashboardResponse = z.object({ | |
| received_usd: true, | ||
| spent_usd: true, | ||
| }), | ||
| addresses: z.record( | ||
| z.string(), AddressSchema | ||
| ), | ||
| addresses: z.record(z.string(), AddressSchema), | ||
| transactions: z.array(z.string()), | ||
| utxo: UtxosSchema.and(z.object({ | ||
| address: z.string(), | ||
| })).array(), | ||
| utxo: UtxosSchema.and( | ||
| z.object({ | ||
| address: z.string(), | ||
| }) | ||
| ).array(), | ||
| }), | ||
| context: requestContextSchema | ||
| context: requestContextSchema, | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have some context about the need for this patch? A link or anything.
Not mandatory just in case, could be useful for future reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put those links as context in the description of the PR:
But your comment makes me think that I should put that context closer to the codebase itself. A recommendation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose to add the following documentation right next to the patch.