diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 5b72a91..a57d4cc 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,3 +1,7 @@ +# Release 0.3.1.1 + +* fix `Rts.utxo(addr)` implementaion in BCH-JS backen that was using old BITBOX REST endpoint. + # Release 0.3.1.0 This is a minor feature release focusing on SDK improvements. See migration guide in docs for details. diff --git a/spedn-js/rts-bchjs/package.json b/spedn-js/rts-bchjs/package.json index e8509b0..c1780e5 100644 --- a/spedn-js/rts-bchjs/package.json +++ b/spedn-js/rts-bchjs/package.json @@ -1,6 +1,6 @@ { "name": "@spedn/rts-bchjs", - "version": "3.1.0", + "version": "3.1.1", "description": "Runtime System for Spedn Contracts with BCH-JS adapter", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -26,7 +26,7 @@ ], "dependencies": { "@chris.troutner/bch-js": "^3.4.1", - "@spedn/rts": "^3.1.0" + "@spedn/rts": "^3.1.1" }, "devDependencies": { "@types/node": "^14.0.27", diff --git a/spedn-js/rts-bchjs/src/rts-bchjs.ts b/spedn-js/rts-bchjs/src/rts-bchjs.ts index 52bda59..5df3fbb 100644 --- a/spedn-js/rts-bchjs/src/rts-bchjs.ts +++ b/spedn-js/rts-bchjs/src/rts-bchjs.ts @@ -1,5 +1,5 @@ import BCHJS from "@chris.troutner/bch-js"; -import { Addresses, Crypto, Rts, RtsECPair, RtsTransactionBuilder, Script } from "@spedn/rts"; +import { Addresses, Crypto, Rts, RtsECPair, RtsTransactionBuilder, Script, UtxoResult } from "@spedn/rts"; import Bitcoin from "bitcoincashjs-lib"; const defaultConfigs: { [network: string]: any } = { @@ -15,8 +15,17 @@ export class BchJsRts extends Rts { this.bchjs = bchjs || new BCHJS(defaultConfigs[network]); } - utxo(addr: any) { - return this.bchjs.Address.utxo(addr); + async utxo(addr: string): Promise { + const result = await this.bchjs.Electrumx.utxo(addr); + return { + ...result, + utxos: result.utxos.map((o: any) => ({ + ...o, + txid: o.tx_hash, + vout: o.tx_pos, + satoshis: o.value + })) + }; } ecPair(ecPair: Bitcoin.ECPair): RtsECPair { diff --git a/spedn-js/rts-bchjs/src/types.d.ts b/spedn-js/rts-bchjs/src/types.d.ts index 3cb3554..20aa823 100644 --- a/spedn-js/rts-bchjs/src/types.d.ts +++ b/spedn-js/rts-bchjs/src/types.d.ts @@ -4,6 +4,7 @@ declare module "@chris.troutner/bch-js" { constructor(conf: any); Address: any; Crypto: any; + Electrumx: any; Script: any; Mnemonic: any; HDNode: any; diff --git a/spedn-js/rts-bchjs/yarn.lock b/spedn-js/rts-bchjs/yarn.lock index 535dc0a..3f15314 100644 --- a/spedn-js/rts-bchjs/yarn.lock +++ b/spedn-js/rts-bchjs/yarn.lock @@ -252,10 +252,10 @@ resolved "https://registry.yarnpkg.com/@istanbuljs/schema/-/schema-0.1.2.tgz#26520bf09abe4a5644cd5414e37125a8954241dd" integrity sha512-tsAQNx32a8CoFhjhijUIhI4kccIAgmGhy8LZMZgGfmXcpMbPRUqn5LWmgRttILi6yeGmBJd2xsPkFMs0PzgPCw== -"@spedn/rts@^3.1.0": - version "3.1.0" - resolved "https://registry.yarnpkg.com/@spedn/rts/-/rts-3.1.0.tgz#090118f57964a7e2c2ac6d9d61a47637ea10af5a" - integrity sha512-fYAGRiMKPE/UZjNTkwLYv3Nvry740H15yeC5+oNIYAT85SP3E3mY9VFyxjK6EUWFtTB+Px+/N73t0HgqBLs37w== +"@spedn/rts@^3.1.1": + version "3.1.1" + resolved "https://registry.yarnpkg.com/@spedn/rts/-/rts-3.1.1.tgz#b45b2cb49df994f448aca5c490696f942544699d" + integrity sha512-r3YjixGB/zLXq/kcnypx6oKSVm2fri+LW+PrExB3u/5Tu0gorUieHd33KWaKaSWYam3VKTBeyzPADoAq96EAtw== dependencies: lodash "^4.17.20" varuint-bitcoin "1.1.2" diff --git a/spedn-js/rts-bitbox/package.json b/spedn-js/rts-bitbox/package.json index 611c017..e355130 100644 --- a/spedn-js/rts-bitbox/package.json +++ b/spedn-js/rts-bitbox/package.json @@ -1,6 +1,6 @@ { "name": "@spedn/rts-bitbox", - "version": "3.1.0", + "version": "3.1.1", "description": "Runtime System for Spedn Contracts with BITBOX adapter", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -25,7 +25,7 @@ "bitcoincash:qrc2jhalczuka8q3dvk0g8mnkqx79wxp9gvvqvg7qt" ], "dependencies": { - "@spedn/rts": "^3.1.0", + "@spedn/rts": "^3.1.1", "bitbox-sdk": "^8.11.2" }, "devDependencies": { diff --git a/spedn-js/rts-bitbox/src/rts-bitbox.ts b/spedn-js/rts-bitbox/src/rts-bitbox.ts index cf7e821..72044d4 100644 --- a/spedn-js/rts-bitbox/src/rts-bitbox.ts +++ b/spedn-js/rts-bitbox/src/rts-bitbox.ts @@ -1,5 +1,6 @@ -import { Addresses, Crypto, Rts, RtsECPair, RtsTransactionBuilder, Script } from "@spedn/rts"; +import { Addresses, Crypto, Rts, RtsECPair, RtsTransactionBuilder, Script, UtxoResult } from "@spedn/rts"; import { BITBOX, TREST_URL, TWS_URL } from "bitbox-sdk"; +import { AddressUtxoResult } from "bitcoin-com-rest"; import Bitcoin from "bitcoincashjs-lib"; const defaultConfigs: { [network: string]: any } = { @@ -15,8 +16,8 @@ export class BitboxRts extends Rts { this.bitbox = bitbox || new BITBOX(defaultConfigs[network]); } - utxo(addr: any) { - return this.bitbox.Address.utxo(addr); + utxo(addr: string): Promise { + return this.bitbox.Address.utxo(addr) as any; } ecPair(ecPair: Bitcoin.ECPair): RtsECPair { diff --git a/spedn-js/rts-bitbox/yarn.lock b/spedn-js/rts-bitbox/yarn.lock index b81785e..701630f 100644 --- a/spedn-js/rts-bitbox/yarn.lock +++ b/spedn-js/rts-bitbox/yarn.lock @@ -213,10 +213,10 @@ resolved "https://registry.yarnpkg.com/@istanbuljs/schema/-/schema-0.1.2.tgz#26520bf09abe4a5644cd5414e37125a8954241dd" integrity sha512-tsAQNx32a8CoFhjhijUIhI4kccIAgmGhy8LZMZgGfmXcpMbPRUqn5LWmgRttILi6yeGmBJd2xsPkFMs0PzgPCw== -"@spedn/rts@^3.1.0": - version "3.1.0" - resolved "https://registry.yarnpkg.com/@spedn/rts/-/rts-3.1.0.tgz#090118f57964a7e2c2ac6d9d61a47637ea10af5a" - integrity sha512-fYAGRiMKPE/UZjNTkwLYv3Nvry740H15yeC5+oNIYAT85SP3E3mY9VFyxjK6EUWFtTB+Px+/N73t0HgqBLs37w== +"@spedn/rts@^3.1.1": + version "3.1.1" + resolved "https://registry.yarnpkg.com/@spedn/rts/-/rts-3.1.1.tgz#b45b2cb49df994f448aca5c490696f942544699d" + integrity sha512-r3YjixGB/zLXq/kcnypx6oKSVm2fri+LW+PrExB3u/5Tu0gorUieHd33KWaKaSWYam3VKTBeyzPADoAq96EAtw== dependencies: lodash "^4.17.20" varuint-bitcoin "1.1.2" diff --git a/spedn-js/rts/package.json b/spedn-js/rts/package.json index af1bf9a..2578887 100644 --- a/spedn-js/rts/package.json +++ b/spedn-js/rts/package.json @@ -1,6 +1,6 @@ { "name": "@spedn/rts", - "version": "3.1.0", + "version": "3.1.1", "description": "Runtime System for Spedn contracts.", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/spedn-js/rts/src/contracts.ts b/spedn-js/rts/src/contracts.ts index 958b6db..82ecc3f 100644 --- a/spedn-js/rts/src/contracts.ts +++ b/spedn-js/rts/src/contracts.ts @@ -79,7 +79,6 @@ export interface Utxo { amount: number; satoshis: number; height: number; - confirmations: number; } export interface Coin { diff --git a/spedn-js/rts/src/rts.ts b/spedn-js/rts/src/rts.ts index 7381fb6..8495679 100644 --- a/spedn-js/rts/src/rts.ts +++ b/spedn-js/rts/src/rts.ts @@ -1,11 +1,11 @@ -import { Module, ModuleFactory, PortableModule } from "./contracts"; +import { Module, ModuleFactory, PortableModule, Utxo } from "./contracts"; export abstract class Rts { private moduleFactory: ModuleFactory; constructor(public readonly network: string = "mainnet") { this.moduleFactory = new ModuleFactory(this); } - abstract utxo(addr: any): any; + abstract utxo(addr: string): Promise; abstract ecPair(ecPair: any): RtsECPair; abstract get addresses(): Addresses; abstract get crypto(): Crypto; @@ -18,6 +18,11 @@ export abstract class Rts { } } +export interface UtxoResult { + success: boolean; + utxos: Utxo[]; +} + export interface Addresses { fromOutputScript(script: Buffer, network: string): string; toHash160(addr: string): string; diff --git a/spedn-js/sdk/package.json b/spedn-js/sdk/package.json index ae5fcf9..4f0f445 100644 --- a/spedn-js/sdk/package.json +++ b/spedn-js/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@spedn/sdk", - "version": "3.1.0", + "version": "3.1.1", "description": "Spedn compiler SDK", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -28,7 +28,7 @@ "author": "{o} Software", "license": "MIT", "dependencies": { - "@spedn/rts": "^3.1.0" + "@spedn/rts": "^3.1.1" }, "devDependencies": { "@types/node": "^14.0.27", diff --git a/spedn-js/sdk/yarn.lock b/spedn-js/sdk/yarn.lock index da17e06..cd872ca 100644 --- a/spedn-js/sdk/yarn.lock +++ b/spedn-js/sdk/yarn.lock @@ -2,10 +2,10 @@ # yarn lockfile v1 -"@spedn/rts@^3.1.0": - version "3.1.0" - resolved "https://registry.yarnpkg.com/@spedn/rts/-/rts-3.1.0.tgz#090118f57964a7e2c2ac6d9d61a47637ea10af5a" - integrity sha512-fYAGRiMKPE/UZjNTkwLYv3Nvry740H15yeC5+oNIYAT85SP3E3mY9VFyxjK6EUWFtTB+Px+/N73t0HgqBLs37w== +"@spedn/rts@^3.1.1": + version "3.1.1" + resolved "https://registry.yarnpkg.com/@spedn/rts/-/rts-3.1.1.tgz#b45b2cb49df994f448aca5c490696f942544699d" + integrity sha512-r3YjixGB/zLXq/kcnypx6oKSVm2fri+LW+PrExB3u/5Tu0gorUieHd33KWaKaSWYam3VKTBeyzPADoAq96EAtw== dependencies: lodash "^4.17.20" varuint-bitcoin "1.1.2" diff --git a/spedn-js/tests/src/rest.test.ts b/spedn-js/tests/src/rest.test.ts new file mode 100644 index 0000000..8c9a35c --- /dev/null +++ b/spedn-js/tests/src/rest.test.ts @@ -0,0 +1,25 @@ +import BCHJS from "@chris.troutner/bch-js"; +import { P2PKHFactory } from "@spedn/rts"; +import { BchJsRts } from "@spedn/rts-bchjs"; +import { BitboxRts } from "@spedn/rts-bitbox"; +import { BITBOX } from "bitbox-sdk"; + +const bchjs = new BCHJS({ restURL: "https://testnet3.fullstack.cash/v3/" }); +const bitbox = new BITBOX({ restURL: "https://trest.bitcoin.com/v2/" }); + +describe.each([ + new BchJsRts("testnet", bchjs) + // new BitboxRts("testnet", bitbox) // tREST seems to be dysfunctional +])("%s REST API", rts => { + it("can find coins", async () => { + const factory = new P2PKHFactory(rts); + // testnet : draw parade crater busy book swim soldier tragic exit feel top civil : m/44'/145'/0'/0/3 + const account = factory.fromAddress("bchtest:qzca95r68adkek2we4jvws5dex6pwg3vt52mkhsqjg"); + const [coin] = await account.findCoins("testnet"); + expect(coin).toBeDefined(); + expect(coin).toHaveProperty("utxo.txid"); + expect(coin).toHaveProperty("utxo.vout"); + expect(coin).toHaveProperty("utxo.satoshis"); + expect(coin).toHaveProperty("utxo.height"); + }); +}); diff --git a/spedn-js/tests/yarn.lock b/spedn-js/tests/yarn.lock index 58d7bd5..255d329 100644 --- a/spedn-js/tests/yarn.lock +++ b/spedn-js/tests/yarn.lock @@ -564,27 +564,29 @@ "@sinonjs/commons" "^1.7.0" "@spedn/rts-bchjs@../rts-bchjs": - version "1.0.0" + version "3.1.1" dependencies: "@chris.troutner/bch-js" "^3.4.1" - "@spedn/rts" "../rts" + "@spedn/rts" "^3.1.1" "@spedn/rts-bitbox@../rts-bitbox": - version "1.0.0" + version "3.1.1" dependencies: - "@spedn/rts" "../rts" + "@spedn/rts" "^3.1.1" bitbox-sdk "^8.11.2" -"@spedn/rts@../rts": - version "3.1.0" +"@spedn/rts@^3.1.1": + version "3.1.1" + resolved "https://registry.yarnpkg.com/@spedn/rts/-/rts-3.1.1.tgz#b45b2cb49df994f448aca5c490696f942544699d" + integrity sha512-r3YjixGB/zLXq/kcnypx6oKSVm2fri+LW+PrExB3u/5Tu0gorUieHd33KWaKaSWYam3VKTBeyzPADoAq96EAtw== dependencies: lodash "^4.17.20" varuint-bitcoin "1.1.2" "@spedn/sdk@../sdk": - version "1.0.0" + version "3.1.1" dependencies: - "@spedn/rts" "../rts" + "@spedn/rts" "^3.1.1" "@transloadit/prettier-bytes@0.0.7": version "0.0.7"