Skip to content

Commit

Permalink
Merge branch 'master' into docs/ordinal-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjeatt authored Nov 1, 2023
2 parents 162a1f5 + 57c9927 commit 0aac8d9
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sdk-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: "20"
registry-url: "https://registry.npmjs.org"
Expand Down
4 changes: 2 additions & 2 deletions docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const config = {
organizationName: "bob-collective",
projectName: "bob",

onBrokenLinks: "throw",
onBrokenMarkdownLinks: "throw",
onBrokenLinks: "warn",
onBrokenMarkdownLinks: "warn",

// Even if you don't use internalization, you can use this field to set useful
// metadata like html lang. For example, if your site is Chinese, you may want
Expand Down
18 changes: 13 additions & 5 deletions sdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"devDependencies": {
"@types/chai": "^4.3.6",
"@types/mocha": "^10.0.2",
"@types/node": "^20.8.3",
"@types/node": "^20.8.9",
"chai": "^4.3.10",
"ecpair": "^2.1.0",
"mocha": "^10.2.0",
Expand Down
43 changes: 43 additions & 0 deletions sdk/src/electrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ export interface MerkleProof {
pos: number,
}

/**
* @ignore
*/
export interface UTXO {
txid: string
vout: number,
value: number,
}

export interface ElectrsClient {
/**
* Get the block hash of the Bitcoin block at a specific height.
Expand Down Expand Up @@ -122,6 +131,14 @@ export interface ElectrsClient {
*/
getFeeEstimate(confirmationTarget: number): Promise<number>;

/**
* Get the Unspent Transaction Outputs (UTXOs) for an address.
*
* @param {string} address - The Bitcoin address to checl.
* @returns {Promise<Array<UTXO>>} A promise that resolves to an array of UTXOs.
*/
getAddressUtxos(address: string): Promise<Array<UTXO>>;

/**
* Broadcast a raw transaction to the network.
*
Expand Down Expand Up @@ -231,6 +248,32 @@ export class DefaultElectrsClient implements ElectrsClient {
return response[confirmationTarget];
}

/**
* @ignore
*/
async getAddressUtxos(address: string, confirmed?: boolean): Promise<Array<UTXO>> {
const response = await this.getJson<Array<{
txid: string,
vout: number,
status: {
confirmed: boolean,
block_height: number,
block_hash: string,
block_time: number
},
value: number,
}>>(`${this.basePath}/address/${address}/utxo`);
return response
.filter(utxo => (typeof confirmed !== "undefined") ? confirmed === utxo.status.confirmed : true)
.map<UTXO>(utxo => {
return {
txid: utxo.txid,
vout: utxo.vout,
value: utxo.value
}
});
}

/**
* @ignore
*/
Expand Down

0 comments on commit 0aac8d9

Please sign in to comment.