@mijoco/stx_helpers
Advanced tools
Comparing version 0.2.1 to 0.2.2
@@ -58,10 +58,2 @@ import * as btc from '@scure/btc-signer'; | ||
export declare function readDepositValue(outputs: Array<any>): number; | ||
/** | ||
* | ||
* @param network | ||
* @param txHex | ||
* @returns | ||
*/ | ||
export declare function parsePayloadFromTransaction(api: string, network: string, txHex: string): Promise<PayloadType>; | ||
export declare function findTransactionByTxId(api: string, txId: string): Promise<any>; | ||
export declare function parsePayloadFromOutput(network: string, tx: btc.Transaction): PayloadType; | ||
@@ -68,0 +60,0 @@ /** |
@@ -25,11 +25,2 @@ "use strict"; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -50,4 +41,2 @@ exports.PrincipalType = exports.PEGOUT_OPCODE = exports.PEGIN_OPCODE = exports.MAGIC_BYTES_MAINNET_NAK = exports.MAGIC_BYTES_MAINNET = exports.MAGIC_BYTES_TESTNET_NAK = exports.MAGIC_BYTES_TESTNET = void 0; | ||
exports.readDepositValue = readDepositValue; | ||
exports.parsePayloadFromTransaction = parsePayloadFromTransaction; | ||
exports.findTransactionByTxId = findTransactionByTxId; | ||
exports.parsePayloadFromOutput = parsePayloadFromOutput; | ||
@@ -389,42 +378,2 @@ exports.getDataToSign = getDataToSign; | ||
} | ||
/** | ||
* | ||
* @param network | ||
* @param txHex | ||
* @returns | ||
*/ | ||
function parsePayloadFromTransaction(api, network, txHex) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const tx = btc.Transaction.fromRaw(base_1.hex.decode(txHex), { allowUnknowInput: true, allowUnknowOutput: true, allowUnknownOutputs: true, allowUnknownInputs: true }); | ||
const out0 = tx.getOutput(0); | ||
const script0 = out0.script; | ||
const spendScr = btc.OutScript.decode(script0); | ||
let payload = {}; | ||
if (spendScr.type === 'unknown') { | ||
if (!tx.getOutput(1) || !tx.getOutput(1).script) | ||
throw new Error('no output 1'); | ||
payload = parsePayloadFromOutput(network, tx); | ||
if (payload.opcode === '3C') | ||
payload.amountSats = Number(tx.getOutput(1).amount); | ||
} | ||
else if (spendScr.type === 'tr') { | ||
// op_drop commits do not contain the payload data ! | ||
const revealerTx = yield findTransactionByTxId(api, tx.id); | ||
payload = { | ||
//mode: RevealerTxModes.OP_DROP, | ||
amountSats: (revealerTx) ? revealerTx.amountSats : 0, | ||
opcode: '3C', | ||
}; | ||
} | ||
return payload; | ||
}); | ||
} | ||
function findTransactionByTxId(api, txId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const path = `${api}/transactions/get-revealer-transactions-by-txid/${txId}`; | ||
const response = yield fetch(path); | ||
const res = yield response.json(); | ||
return res; | ||
}); | ||
} | ||
function parsePayloadFromOutput(network, tx) { | ||
@@ -431,0 +380,0 @@ //const out0 = tx.getOutput(0) |
@@ -244,3 +244,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const url = mempoolUrl + '/address/' + address; | ||
const url = `${mempoolUrl}/address/${address}`; | ||
const response = yield fetch(url); | ||
@@ -247,0 +247,0 @@ const result = yield response.json(); |
@@ -10,3 +10,2 @@ import { StacksMainnet, StacksTestnet } from "@stacks/network"; | ||
export declare function getPoxInfo(stacksApi: string): Promise<any>; | ||
export declare function fetchExchangeRates(stxEcoApi: string): Promise<any>; | ||
export declare function callContractReadOnly(stacksApi: string, data: any): Promise<any>; |
@@ -19,3 +19,2 @@ "use strict"; | ||
exports.getPoxInfo = getPoxInfo; | ||
exports.fetchExchangeRates = fetchExchangeRates; | ||
exports.callContractReadOnly = callContractReadOnly; | ||
@@ -98,15 +97,2 @@ const network_1 = require("@stacks/network"); | ||
} | ||
function fetchExchangeRates(stxEcoApi) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const path = `${stxEcoApi}/btc/tx/rates`; | ||
try { | ||
const response = yield fetch(path); | ||
const res = yield response.json(); | ||
return res; | ||
} | ||
catch (err) { | ||
return undefined; | ||
} | ||
}); | ||
} | ||
function callContractReadOnly(stacksApi, data) { | ||
@@ -113,0 +99,0 @@ return __awaiter(this, void 0, void 0, function* () { |
{ | ||
"name": "@mijoco/stx_helpers", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "types": "dist/index.d.ts", |
11
93560
2594