Skip to content

Commit

Permalink
Merge pull request #3 from jordankzf/jordankzf/improvements
Browse files Browse the repository at this point in the history
refactor: multiple improvements & bug fixes
  • Loading branch information
iamcrazycoder authored Jul 14, 2023
2 parents c4c1966 + 978443a commit 679a6f8
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 15 deletions.
14 changes: 10 additions & 4 deletions examples/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@
1. `npm i`

2. To inscribe:
- Open `inscribe.js` and edit accordingly.
- Run with `npm run inscribe`.

- Open `inscribe.js` and edit accordingly.
- Run with `npm run inscribe`.

3. To query a specific inscription for metadata:
- Open `read.js` and edit accordingly.
- Run with `npm run read`.

- Open `read.js` and edit accordingly.
- Run with `npm run read`.

4. To send cardinals (safe spendables, e.g. satas that do not have inscriptions and are not rare ordinals):
- Open `send.js` and edit accordingly.
- Run with `npm run send`.
3 changes: 2 additions & 1 deletion examples/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"type": "module",
"scripts": {
"inscribe": "node inscribe",
"read": "node read"
"read": "node read",
"send": "node send"
},
"author": "",
"license": "ISC",
Expand Down
31 changes: 31 additions & 0 deletions examples/node/send.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ordit } from "@sadoprotocol/ordit-sdk"; //import Ordit

async function main() {
// Replace accordingly
const psbtTemplate = {
format: "p2wpkh",
network: "testnet",
pubKey: "02950611fedb407d34cc845101f2bdfb2e7e3ec075e1424015bbf2db75c8ebe696",
ins: [
{
address: "tb1qzxtxwhsqkh0yp6ne0mpefu99gn49a945m9hc28"
}
],
outs: [
{
address: "tb1qzxtxwhsqkh0yp6ne0mpefu99gn49a945m9hc28",
cardinals: 1337
}
]
};

// You need to sign this externally (tip: try window.unisat.signPsbt)
const psbt = await ordit.transactions.createPsbt(psbtTemplate);
console.log(psbt);

const hex = "your signed PSBT hex here";
const txId = await ordit.transactions.relayTransaction(hex, "testnet");
console.log(txId);
}

main();
5 changes: 5 additions & 0 deletions packages/sdk/src/addresses/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export function getAddressFormat(address: string, network: Network) {
return format;
}

export function getAddressType(address: string, network: Network): AddressTypes {
const addressFormat = getAddressFormat(address, network).format;
return addressNameToType[addressFormat as AddressFormats];
}

export function getAddressesFromPublicKey(
pubKey: string | Buffer,
network: Network = "testnet",
Expand Down
6 changes: 2 additions & 4 deletions packages/sdk/src/transactions/relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import { OrditApi } from "../api";
import { Network } from "../config/types";

export async function relayTransaction(hex: string, network: Network) {
const txResponse = await OrditApi.fetch<{ success: boolean; rdata: Array<any> }>("utxo/relay", {
const txResponse = await OrditApi.fetch<{ success: boolean; rdata: string }>("utxo/relay", {
data: { hex },
network: network
});

if (txResponse.success && txResponse.rdata) {
return {
txid: txResponse.rdata
};
return txResponse.rdata;
}

throw new Error("Failed to relay transaction.");
Expand Down
6 changes: 2 additions & 4 deletions packages/sdk/src/wallet/Ordit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export class Ordit {
throw new Error("Invalid options provided.");
}

const txResponse = await OrditApi.fetch<{ success: boolean; rdata: Array<any> }>("utxo/relay", {
const txResponse = await OrditApi.fetch<{ success: boolean; rdata: string }>("utxo/relay", {
data: { hex },
network: network ?? this.#network
});
Expand All @@ -270,9 +270,7 @@ export class Ordit {
throw new Error("Failed to relay transaction.");
}

return {
txid: txResponse.rdata
};
return txResponse.rdata;
}

async getInscriptions() {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/wallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export async function getWalletWithBalances(options: GetWalletOptions) {
const unspent = await OrditApi.fetch<{ success: boolean; rdata: Array<any> }>("utxo/unspents", {
network: options.network,
data: {
address,
address: address.address,
options: {
txhex: true,
notsafetospend: false,
Expand Down
3 changes: 2 additions & 1 deletion packages/sdk/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
"outDir": "./dist",
"sourceMap": true,
},
"exclude": ["./tests"]
}
1 change: 1 addition & 0 deletions packages/sdk/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"rootDir": "./",
"outDir": "./dist",
"sourceMap": true,
},
"include": ["./src", "./tests", "./src/types"]
}

0 comments on commit 679a6f8

Please sign in to comment.