Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ abstract class Connection extends EventEmitter {
this.emit('state', state);
}

/**
* Some connection managers may need to run some action when the wallet is ready.
*/
notifyWalletReady() {
return;
}

/**
* Connect to the server and start emitting events.
**/
Expand Down
26 changes: 3 additions & 23 deletions src/models/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import ScriptData from './script_data'
import Network from './network'
import { bytesToOutputValue, unpackLen, unpackToInt, intToBytes, signedIntToBytes } from '../utils/buffer';
import { prettyValue } from '../utils/numbers';
import {parseP2PKH, parseP2SH, parseScriptData} from '../utils/scripts'
import {parseP2PKH, parseP2SH, parseScriptData, parseScript} from '../utils/scripts'
import _ from 'lodash'

type optionsType = {
Expand Down Expand Up @@ -178,28 +178,8 @@ class Output {
// we can keep throwing the error. Otherwise, we should just return null
// because this method will be used together with others when we are trying to parse a given script.

try {
let parsedScript;
if (P2PKH.identify(this.script)) {
// This is a P2PKH script
parsedScript = parseP2PKH(this.script, network);
} else if (P2SH.identify(this.script)) {
// This is a P2SH script
parsedScript = parseP2SH(this.script, network);
} else {
// defaults to data script
parsedScript = parseScriptData(this.script);
}
this.decodedScript = parsedScript;
return parsedScript;
} catch (error) {
if (error instanceof ParseError) {
// We don't know how to parse this script
return null;
} else {
throw error;
}
}
this.decodedScript = parseScript(this.script, network);
return this.decodedScript;
}

/**
Expand Down
14 changes: 14 additions & 0 deletions src/models/p2pkh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { util } from 'bitcore-lib';
import { intToBytes } from '../utils/buffer';
import helpers from '../utils/helpers';
import Address from './address';
import { IHistoryOutputDecoded } from '../types';

type optionsType = {
timelock?: number | null | undefined,
Expand Down Expand Up @@ -75,6 +76,19 @@ class P2PKH {
return util.buffer.concat(arr);
}

/**
* Get decoded output.
*
* @return {IHistoryOutputDecoded}
*/
getDecoded(): IHistoryOutputDecoded {
return {
type: this.getType(),
address: this.address.base58,
timelock: this.timelock,
}
}

/**
* Identify a script as P2PKH or not.
*
Expand Down
14 changes: 14 additions & 0 deletions src/models/p2sh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { util } from 'bitcore-lib';
import helpers from '../utils/helpers';
import { intToBytes } from '../utils/buffer';
import Address from './address';
import { IHistoryOutputDecoded } from '../types';

type optionsType = {
timelock?: number | null | undefined,
Expand Down Expand Up @@ -71,6 +72,19 @@ class P2SH {
return util.buffer.concat(arr);
}

/**
* Get decoded output.
*
* @return {IHistoryOutputDecoded}
*/
getDecoded(): IHistoryOutputDecoded {
return {
type: this.getType(),
address: this.address.base58,
timelock: this.timelock,
}
}

/**
* Identify a script as P2SH or not.
*
Expand Down
17 changes: 15 additions & 2 deletions src/models/script_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { OP_CHECKSIG } from '../opcodes';
import { util } from 'bitcore-lib';
import helpers from '../utils/helpers';
import buffer from 'buffer';
import { IHistoryOutputDecoded } from '../types';

class ScriptData {
// String of data to store on the script
Expand All @@ -25,11 +26,11 @@ class ScriptData {
/**
* Get script type
*
* @return {String}
* @return {string}
* @memberof ScriptData
* @inner
*/
getType(): String {
getType(): 'data' {
return 'data';
}

Expand All @@ -47,6 +48,18 @@ class ScriptData {
arr.push(OP_CHECKSIG);
return util.buffer.concat(arr);
}

/**
* Get decoded output.
*
* @return {IHistoryOutputDecoded}
*/
getDecoded(): IHistoryOutputDecoded {
return {
type: this.getType(),
data: this.data,
}
}
}

export default ScriptData;
8 changes: 0 additions & 8 deletions src/new/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,4 @@ class WalletConnection extends BaseConnection {
}
}

// TODO: This is to maintain compatibility until we migrate to typescript
// @ts-ignore
WalletConnection.CLOSED = 0;
// @ts-ignore
WalletConnection.CONNECTING = 1;
// @ts-ignore
WalletConnection.CONNECTED = 2;

export default WalletConnection;
Loading