cashscript 0.6.2 → 0.7.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main/Argument.d.ts +1 -1
- package/dist/main/Argument.js +7 -7
- package/dist/main/Errors.d.ts +6 -2
- package/dist/main/Errors.js +10 -2
- package/dist/main/Transaction.js +5 -6
- package/dist/main/interfaces.d.ts +1 -0
- package/dist/main/interfaces.js +1 -0
- package/dist/main/network/BitcoinRpcNetworkProvider.d.ts +7 -7
- package/dist/main/network/ElectrumNetworkProvider.js +5 -1
- package/dist/main/utils.d.ts +2 -1
- package/dist/main/utils.js +10 -1
- package/dist/module/Argument.d.ts +1 -1
- package/dist/module/Argument.js +7 -7
- package/dist/module/Errors.d.ts +6 -2
- package/dist/module/Errors.js +8 -1
- package/dist/module/Transaction.js +6 -7
- package/dist/module/index.js +2 -1
- package/dist/module/interfaces.d.ts +1 -0
- package/dist/module/interfaces.js +1 -0
- package/dist/module/network/BitcoinRpcNetworkProvider.d.ts +7 -7
- package/dist/module/network/ElectrumNetworkProvider.js +5 -1
- package/dist/module/utils.d.ts +2 -1
- package/dist/module/utils.js +11 -3
- package/package.json +2 -2
package/dist/main/Argument.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import SignatureTemplate from './SignatureTemplate';
|
|
2
|
-
export declare type Argument = number | boolean | string | Uint8Array | SignatureTemplate;
|
|
2
|
+
export declare type Argument = number | bigint | boolean | string | Uint8Array | SignatureTemplate;
|
|
3
3
|
export declare function encodeArgument(argument: Argument, typeStr: string): Uint8Array | SignatureTemplate;
|
package/dist/main/Argument.js
CHANGED
|
@@ -17,7 +17,7 @@ function encodeArgument(argument, typeStr) {
|
|
|
17
17
|
return utils_1.encodeBool(argument);
|
|
18
18
|
}
|
|
19
19
|
if (type === utils_1.PrimitiveType.INT) {
|
|
20
|
-
if (typeof argument !== 'number') {
|
|
20
|
+
if (typeof argument !== 'number' && typeof argument !== 'bigint') {
|
|
21
21
|
throw new Errors_1.TypeError(typeof argument, type);
|
|
22
22
|
}
|
|
23
23
|
return utils_1.encodeInt(argument);
|
|
@@ -42,14 +42,14 @@ function encodeArgument(argument, typeStr) {
|
|
|
42
42
|
}
|
|
43
43
|
// Redefine SIG as a bytes65 so it is included in the size checks below
|
|
44
44
|
// Note that ONLY Schnorr signatures are accepted
|
|
45
|
-
if (type === utils_1.PrimitiveType.SIG) {
|
|
45
|
+
if (type === utils_1.PrimitiveType.SIG && argument.byteLength !== 0) {
|
|
46
46
|
type = new utils_1.BytesType(65);
|
|
47
47
|
}
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
// Redefine SIG as a bytes64 so it is included in the size checks below
|
|
49
|
+
// Note that ONLY Schnorr signatures are accepted
|
|
50
|
+
if (type === utils_1.PrimitiveType.DATASIG && argument.byteLength !== 0) {
|
|
51
|
+
type = new utils_1.BytesType(64);
|
|
52
|
+
}
|
|
53
53
|
// Bounded bytes types require a correctly sized argument
|
|
54
54
|
if (type instanceof utils_1.BytesType && type.bound && argument.byteLength !== type.bound) {
|
|
55
55
|
throw new Errors_1.TypeError(`bytes${argument.byteLength}`, type);
|
package/dist/main/Errors.d.ts
CHANGED
|
@@ -2,6 +2,9 @@ import { Type } from '@cashscript/utils';
|
|
|
2
2
|
export declare class TypeError extends Error {
|
|
3
3
|
constructor(actual: string, expected: Type);
|
|
4
4
|
}
|
|
5
|
+
export declare class OutputSatoshisTooSmallError extends Error {
|
|
6
|
+
constructor(satoshis: number);
|
|
7
|
+
}
|
|
5
8
|
export declare class FailedTransactionError extends Error {
|
|
6
9
|
reason: string;
|
|
7
10
|
meep: string;
|
|
@@ -28,7 +31,7 @@ export declare enum Reason {
|
|
|
28
31
|
SIG_COUNT = "Signature count negative or greater than pubkey count",
|
|
29
32
|
PUBKEY_COUNT = "Pubkey count negative or limit exceeded",
|
|
30
33
|
INVALID_OPERAND_SIZE = "Invalid operand size",
|
|
31
|
-
INVALID_NUMBER_RANGE = "Given operand is not a number within the valid range
|
|
34
|
+
INVALID_NUMBER_RANGE = "Given operand is not a number within the valid range",
|
|
32
35
|
IMPOSSIBLE_ENCODING = "The requested encoding is impossible to satisfy",
|
|
33
36
|
INVALID_SPLIT_RANGE = "Invalid OP_SPLIT range",
|
|
34
37
|
INVALID_BIT_COUNT = "Invalid number of bit set in OP_CHECKMULTISIG",
|
|
@@ -58,5 +61,6 @@ export declare enum Reason {
|
|
|
58
61
|
CLEANSTACK = "Script did not clean its stack",
|
|
59
62
|
NONCOMPRESSED_PUBKEY = "Using non-compressed public key",
|
|
60
63
|
ILLEGAL_FORKID = "Illegal use of SIGHASH_FORKID",
|
|
61
|
-
MUST_USE_FORKID = "Signature must use SIGHASH_FORKID"
|
|
64
|
+
MUST_USE_FORKID = "Signature must use SIGHASH_FORKID",
|
|
65
|
+
UNKNOWN = "unknown error"
|
|
62
66
|
}
|
package/dist/main/Errors.js
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Reason = exports.FailedSigCheckError = exports.FailedTimeCheckError = exports.FailedRequireError = exports.FailedTransactionError = exports.TypeError = void 0;
|
|
3
|
+
exports.Reason = exports.FailedSigCheckError = exports.FailedTimeCheckError = exports.FailedRequireError = exports.FailedTransactionError = exports.OutputSatoshisTooSmallError = exports.TypeError = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
4
5
|
class TypeError extends Error {
|
|
5
6
|
constructor(actual, expected) {
|
|
6
7
|
super(`Found type '${actual}' where type '${expected.toString()}' was expected`);
|
|
7
8
|
}
|
|
8
9
|
}
|
|
9
10
|
exports.TypeError = TypeError;
|
|
11
|
+
class OutputSatoshisTooSmallError extends Error {
|
|
12
|
+
constructor(satoshis) {
|
|
13
|
+
super(`Tried to add an output with ${satoshis} satoshis, which is less than the DUST limit (${constants_1.DUST_LIMIT})`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.OutputSatoshisTooSmallError = OutputSatoshisTooSmallError;
|
|
10
17
|
class FailedTransactionError extends Error {
|
|
11
18
|
constructor(reason, meep) {
|
|
12
19
|
super(`Transaction failed with reason: ${reason}\n${meep}`);
|
|
@@ -41,7 +48,7 @@ var Reason;
|
|
|
41
48
|
Reason["SIG_COUNT"] = "Signature count negative or greater than pubkey count";
|
|
42
49
|
Reason["PUBKEY_COUNT"] = "Pubkey count negative or limit exceeded";
|
|
43
50
|
Reason["INVALID_OPERAND_SIZE"] = "Invalid operand size";
|
|
44
|
-
Reason["INVALID_NUMBER_RANGE"] = "Given operand is not a number within the valid range
|
|
51
|
+
Reason["INVALID_NUMBER_RANGE"] = "Given operand is not a number within the valid range";
|
|
45
52
|
Reason["IMPOSSIBLE_ENCODING"] = "The requested encoding is impossible to satisfy";
|
|
46
53
|
Reason["INVALID_SPLIT_RANGE"] = "Invalid OP_SPLIT range";
|
|
47
54
|
Reason["INVALID_BIT_COUNT"] = "Invalid number of bit set in OP_CHECKMULTISIG";
|
|
@@ -72,5 +79,6 @@ var Reason;
|
|
|
72
79
|
Reason["NONCOMPRESSED_PUBKEY"] = "Using non-compressed public key";
|
|
73
80
|
Reason["ILLEGAL_FORKID"] = "Illegal use of SIGHASH_FORKID";
|
|
74
81
|
Reason["MUST_USE_FORKID"] = "Signature must use SIGHASH_FORKID";
|
|
82
|
+
Reason["UNKNOWN"] = "unknown error";
|
|
75
83
|
})(Reason = exports.Reason || (exports.Reason = {}));
|
|
76
84
|
//# sourceMappingURL=Errors.js.map
|
package/dist/main/Transaction.js
CHANGED
|
@@ -52,15 +52,14 @@ class Transaction {
|
|
|
52
52
|
}
|
|
53
53
|
to(toOrOutputs, amount) {
|
|
54
54
|
if (typeof toOrOutputs === 'string' && typeof amount === 'number') {
|
|
55
|
-
this.
|
|
55
|
+
return this.to([{ to: toOrOutputs, amount }]);
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
if (Array.isArray(toOrOutputs) && amount === undefined) {
|
|
58
|
+
toOrOutputs.forEach(utils_2.validateRecipient);
|
|
58
59
|
this.outputs = this.outputs.concat(toOrOutputs);
|
|
60
|
+
return this;
|
|
59
61
|
}
|
|
60
|
-
|
|
61
|
-
throw new Error('Incorrect arguments passed to function \'to\'');
|
|
62
|
-
}
|
|
63
|
-
return this;
|
|
62
|
+
throw new Error('Incorrect arguments passed to function \'to\'');
|
|
64
63
|
}
|
|
65
64
|
withOpReturn(chunks) {
|
|
66
65
|
this.outputs.push(utils_2.createOpReturnOutput(chunks));
|
package/dist/main/interfaces.js
CHANGED
|
@@ -26,16 +26,16 @@ interface ListUnspentItem {
|
|
|
26
26
|
}
|
|
27
27
|
interface RpcClientRetry {
|
|
28
28
|
constructor(url: string, opts?: object): void;
|
|
29
|
-
listUnspent(
|
|
29
|
+
listUnspent(minConf?: number, maxConf?: number, addresses?: string[], includeUnsafe?: boolean, queryOptions?: object): Promise<ListUnspentItem[]>;
|
|
30
30
|
getBlockCount(): Promise<number>;
|
|
31
|
-
getRawTransaction(txid: string, verbose?: boolean,
|
|
32
|
-
sendRawTransaction(
|
|
33
|
-
generate(
|
|
34
|
-
generateToAddress(
|
|
31
|
+
getRawTransaction(txid: string, verbose?: boolean, blockHash?: string): Promise<string>;
|
|
32
|
+
sendRawTransaction(hexString: string, allowHighFees?: boolean): Promise<string>;
|
|
33
|
+
generate(nBlocks: number, maxTries?: number): Promise<string[]>;
|
|
34
|
+
generateToAddress(nBlocks: number, address: string, maxTries?: number): Promise<string[]>;
|
|
35
35
|
getNewAddress(label?: string): Promise<string>;
|
|
36
36
|
dumpPrivKey(address: string): Promise<string>;
|
|
37
|
-
getBalance(dummy?: string,
|
|
38
|
-
getBlock(
|
|
37
|
+
getBalance(dummy?: string, minConf?: number, includeWatchOnly?: boolean): Promise<number>;
|
|
38
|
+
getBlock(blockHash: string, verbosity?: number): Promise<string>;
|
|
39
39
|
importAddress(address: string, label?: string, rescan?: boolean, p2sh?: boolean): Promise<void>;
|
|
40
40
|
}
|
|
41
41
|
export {};
|
|
@@ -37,12 +37,16 @@ class ElectrumNetworkProvider {
|
|
|
37
37
|
}
|
|
38
38
|
else if (network === interfaces_1.Network.TESTNET) {
|
|
39
39
|
// Initialise a 1-of-2 Electrum Cluster with 2 hardcoded servers
|
|
40
|
-
this.electrum = new electrum_cash_1.ElectrumCluster('CashScript Application', '1.4.1', 1, 2);
|
|
40
|
+
this.electrum = new electrum_cash_1.ElectrumCluster('CashScript Application', '1.4.1', 1, 2, electrum_cash_1.ClusterOrder.PRIORITY);
|
|
41
41
|
this.electrum.addServer('blackie.c3-soft.com', 60004, electrum_cash_1.ElectrumTransport.WSS.Scheme, false);
|
|
42
42
|
this.electrum.addServer('electroncash.de', 60004, electrum_cash_1.ElectrumTransport.WSS.Scheme, false);
|
|
43
43
|
// this.electrum.addServer('bch.loping.net', 60004, ElectrumTransport.WSS.Scheme, false);
|
|
44
44
|
// this.electrum.addServer('testnet.imaginary.cash', 50004, ElectrumTransport.WSS.Scheme);
|
|
45
45
|
}
|
|
46
|
+
else if (network === interfaces_1.Network.STAGING) {
|
|
47
|
+
this.electrum = new electrum_cash_1.ElectrumCluster('CashScript Application', '1.4.1', 1, 1, electrum_cash_1.ClusterOrder.PRIORITY);
|
|
48
|
+
this.electrum.addServer('testnet4.imaginary.cash', 50004, electrum_cash_1.ElectrumTransport.WSS.Scheme, false);
|
|
49
|
+
}
|
|
46
50
|
else {
|
|
47
51
|
throw new Error(`Tried to instantiate an ElectrumNetworkProvider for unsupported network ${network}`);
|
|
48
52
|
}
|
package/dist/main/utils.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Transaction } from '@bitauth/libauth';
|
|
2
2
|
import { Script } from '@cashscript/utils';
|
|
3
|
-
import { Utxo, Output } from './interfaces';
|
|
3
|
+
import { Utxo, Output, Recipient } from './interfaces';
|
|
4
4
|
import { FailedTransactionError } from './Errors';
|
|
5
|
+
export declare function validateRecipient(recipient: Recipient): void;
|
|
5
6
|
export declare function getInputSize(inputScript: Uint8Array): number;
|
|
6
7
|
export declare function getPreimageSize(script: Uint8Array): number;
|
|
7
8
|
export declare function getTxSizeWithoutInputs(outputs: Output[]): number;
|
package/dist/main/utils.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getNetworkPrefix = exports.addressToLockScript = exports.scriptToLockingBytecode = exports.scriptToAddress = exports.meep = exports.buildError = exports.createSighashPreimage = exports.createOpReturnOutput = exports.createInputScript = exports.getTxSizeWithoutInputs = exports.getPreimageSize = exports.getInputSize = void 0;
|
|
3
|
+
exports.getNetworkPrefix = exports.addressToLockScript = exports.scriptToLockingBytecode = exports.scriptToAddress = exports.meep = exports.buildError = exports.createSighashPreimage = exports.createOpReturnOutput = exports.createInputScript = exports.getTxSizeWithoutInputs = exports.getPreimageSize = exports.getInputSize = exports.validateRecipient = void 0;
|
|
4
4
|
const libauth_1 = require("@bitauth/libauth");
|
|
5
5
|
const utils_1 = require("@cashscript/utils");
|
|
6
6
|
const interfaces_1 = require("./interfaces");
|
|
7
7
|
const constants_1 = require("./constants");
|
|
8
8
|
const Errors_1 = require("./Errors");
|
|
9
|
+
// ////////// PARAMETER VALIDATION ////////////////////////////////////////////
|
|
10
|
+
function validateRecipient(recipient) {
|
|
11
|
+
if (recipient.amount < constants_1.DUST_LIMIT) {
|
|
12
|
+
throw new Errors_1.OutputSatoshisTooSmallError(recipient.amount);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.validateRecipient = validateRecipient;
|
|
9
16
|
// ////////// SIZE CALCULATIONS ///////////////////////////////////////////////
|
|
10
17
|
function getInputSize(inputScript) {
|
|
11
18
|
const scriptSize = inputScript.byteLength;
|
|
@@ -161,6 +168,8 @@ function getNetworkPrefix(network) {
|
|
|
161
168
|
switch (network) {
|
|
162
169
|
case interfaces_1.Network.MAINNET:
|
|
163
170
|
return 'bitcoincash';
|
|
171
|
+
case interfaces_1.Network.STAGING:
|
|
172
|
+
return 'bchtest';
|
|
164
173
|
case interfaces_1.Network.TESTNET:
|
|
165
174
|
return 'bchtest';
|
|
166
175
|
case interfaces_1.Network.REGTEST:
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import SignatureTemplate from './SignatureTemplate';
|
|
2
|
-
export declare type Argument = number | boolean | string | Uint8Array | SignatureTemplate;
|
|
2
|
+
export declare type Argument = number | bigint | boolean | string | Uint8Array | SignatureTemplate;
|
|
3
3
|
export declare function encodeArgument(argument: Argument, typeStr: string): Uint8Array | SignatureTemplate;
|
package/dist/module/Argument.js
CHANGED
|
@@ -11,7 +11,7 @@ export function encodeArgument(argument, typeStr) {
|
|
|
11
11
|
return encodeBool(argument);
|
|
12
12
|
}
|
|
13
13
|
if (type === PrimitiveType.INT) {
|
|
14
|
-
if (typeof argument !== 'number') {
|
|
14
|
+
if (typeof argument !== 'number' && typeof argument !== 'bigint') {
|
|
15
15
|
throw new TypeError(typeof argument, type);
|
|
16
16
|
}
|
|
17
17
|
return encodeInt(argument);
|
|
@@ -36,14 +36,14 @@ export function encodeArgument(argument, typeStr) {
|
|
|
36
36
|
}
|
|
37
37
|
// Redefine SIG as a bytes65 so it is included in the size checks below
|
|
38
38
|
// Note that ONLY Schnorr signatures are accepted
|
|
39
|
-
if (type === PrimitiveType.SIG) {
|
|
39
|
+
if (type === PrimitiveType.SIG && argument.byteLength !== 0) {
|
|
40
40
|
type = new BytesType(65);
|
|
41
41
|
}
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
// Redefine SIG as a bytes64 so it is included in the size checks below
|
|
43
|
+
// Note that ONLY Schnorr signatures are accepted
|
|
44
|
+
if (type === PrimitiveType.DATASIG && argument.byteLength !== 0) {
|
|
45
|
+
type = new BytesType(64);
|
|
46
|
+
}
|
|
47
47
|
// Bounded bytes types require a correctly sized argument
|
|
48
48
|
if (type instanceof BytesType && type.bound && argument.byteLength !== type.bound) {
|
|
49
49
|
throw new TypeError(`bytes${argument.byteLength}`, type);
|
package/dist/module/Errors.d.ts
CHANGED
|
@@ -2,6 +2,9 @@ import { Type } from '@cashscript/utils';
|
|
|
2
2
|
export declare class TypeError extends Error {
|
|
3
3
|
constructor(actual: string, expected: Type);
|
|
4
4
|
}
|
|
5
|
+
export declare class OutputSatoshisTooSmallError extends Error {
|
|
6
|
+
constructor(satoshis: number);
|
|
7
|
+
}
|
|
5
8
|
export declare class FailedTransactionError extends Error {
|
|
6
9
|
reason: string;
|
|
7
10
|
meep: string;
|
|
@@ -28,7 +31,7 @@ export declare enum Reason {
|
|
|
28
31
|
SIG_COUNT = "Signature count negative or greater than pubkey count",
|
|
29
32
|
PUBKEY_COUNT = "Pubkey count negative or limit exceeded",
|
|
30
33
|
INVALID_OPERAND_SIZE = "Invalid operand size",
|
|
31
|
-
INVALID_NUMBER_RANGE = "Given operand is not a number within the valid range
|
|
34
|
+
INVALID_NUMBER_RANGE = "Given operand is not a number within the valid range",
|
|
32
35
|
IMPOSSIBLE_ENCODING = "The requested encoding is impossible to satisfy",
|
|
33
36
|
INVALID_SPLIT_RANGE = "Invalid OP_SPLIT range",
|
|
34
37
|
INVALID_BIT_COUNT = "Invalid number of bit set in OP_CHECKMULTISIG",
|
|
@@ -58,5 +61,6 @@ export declare enum Reason {
|
|
|
58
61
|
CLEANSTACK = "Script did not clean its stack",
|
|
59
62
|
NONCOMPRESSED_PUBKEY = "Using non-compressed public key",
|
|
60
63
|
ILLEGAL_FORKID = "Illegal use of SIGHASH_FORKID",
|
|
61
|
-
MUST_USE_FORKID = "Signature must use SIGHASH_FORKID"
|
|
64
|
+
MUST_USE_FORKID = "Signature must use SIGHASH_FORKID",
|
|
65
|
+
UNKNOWN = "unknown error"
|
|
62
66
|
}
|
package/dist/module/Errors.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
import { DUST_LIMIT } from './constants';
|
|
1
2
|
export class TypeError extends Error {
|
|
2
3
|
constructor(actual, expected) {
|
|
3
4
|
super(`Found type '${actual}' where type '${expected.toString()}' was expected`);
|
|
4
5
|
}
|
|
5
6
|
}
|
|
7
|
+
export class OutputSatoshisTooSmallError extends Error {
|
|
8
|
+
constructor(satoshis) {
|
|
9
|
+
super(`Tried to add an output with ${satoshis} satoshis, which is less than the DUST limit (${DUST_LIMIT})`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
6
12
|
export class FailedTransactionError extends Error {
|
|
7
13
|
constructor(reason, meep) {
|
|
8
14
|
super(`Transaction failed with reason: ${reason}\n${meep}`);
|
|
@@ -33,7 +39,7 @@ export var Reason;
|
|
|
33
39
|
Reason["SIG_COUNT"] = "Signature count negative or greater than pubkey count";
|
|
34
40
|
Reason["PUBKEY_COUNT"] = "Pubkey count negative or limit exceeded";
|
|
35
41
|
Reason["INVALID_OPERAND_SIZE"] = "Invalid operand size";
|
|
36
|
-
Reason["INVALID_NUMBER_RANGE"] = "Given operand is not a number within the valid range
|
|
42
|
+
Reason["INVALID_NUMBER_RANGE"] = "Given operand is not a number within the valid range";
|
|
37
43
|
Reason["IMPOSSIBLE_ENCODING"] = "The requested encoding is impossible to satisfy";
|
|
38
44
|
Reason["INVALID_SPLIT_RANGE"] = "Invalid OP_SPLIT range";
|
|
39
45
|
Reason["INVALID_BIT_COUNT"] = "Invalid number of bit set in OP_CHECKMULTISIG";
|
|
@@ -64,5 +70,6 @@ export var Reason;
|
|
|
64
70
|
Reason["NONCOMPRESSED_PUBKEY"] = "Using non-compressed public key";
|
|
65
71
|
Reason["ILLEGAL_FORKID"] = "Illegal use of SIGHASH_FORKID";
|
|
66
72
|
Reason["MUST_USE_FORKID"] = "Signature must use SIGHASH_FORKID";
|
|
73
|
+
Reason["UNKNOWN"] = "unknown error";
|
|
67
74
|
})(Reason || (Reason = {}));
|
|
68
75
|
//# sourceMappingURL=Errors.js.map
|
|
@@ -11,7 +11,7 @@ import { bigIntToBinUint64LE, hexToBin, binToHex, encodeTransaction, addressCont
|
|
|
11
11
|
import delay from 'delay';
|
|
12
12
|
import { hash160, hash256, placeholder, scriptToBytecode, } from '@cashscript/utils';
|
|
13
13
|
import { isSignableUtxo, } from './interfaces';
|
|
14
|
-
import { meep, createInputScript, getInputSize, createOpReturnOutput, getTxSizeWithoutInputs, getPreimageSize, buildError, addressToLockScript, createSighashPreimage, } from './utils';
|
|
14
|
+
import { meep, createInputScript, getInputSize, createOpReturnOutput, getTxSizeWithoutInputs, getPreimageSize, buildError, addressToLockScript, createSighashPreimage, validateRecipient, } from './utils';
|
|
15
15
|
import { P2SH_OUTPUT_SIZE, DUST_LIMIT } from './constants';
|
|
16
16
|
import SignatureTemplate from './SignatureTemplate';
|
|
17
17
|
const bip68 = require('bip68');
|
|
@@ -46,15 +46,14 @@ export class Transaction {
|
|
|
46
46
|
}
|
|
47
47
|
to(toOrOutputs, amount) {
|
|
48
48
|
if (typeof toOrOutputs === 'string' && typeof amount === 'number') {
|
|
49
|
-
this.
|
|
49
|
+
return this.to([{ to: toOrOutputs, amount }]);
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
if (Array.isArray(toOrOutputs) && amount === undefined) {
|
|
52
|
+
toOrOutputs.forEach(validateRecipient);
|
|
52
53
|
this.outputs = this.outputs.concat(toOrOutputs);
|
|
54
|
+
return this;
|
|
53
55
|
}
|
|
54
|
-
|
|
55
|
-
throw new Error('Incorrect arguments passed to function \'to\'');
|
|
56
|
-
}
|
|
57
|
-
return this;
|
|
56
|
+
throw new Error('Incorrect arguments passed to function \'to\'');
|
|
58
57
|
}
|
|
59
58
|
withOpReturn(chunks) {
|
|
60
59
|
this.outputs.push(createOpReturnOutput(chunks));
|
package/dist/module/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { Contract } from './Contract';
|
|
2
2
|
export { Transaction } from './Transaction';
|
|
3
3
|
export { default as SignatureTemplate } from './SignatureTemplate';
|
|
4
|
-
|
|
4
|
+
import * as utils_1 from '@cashscript/utils';
|
|
5
|
+
export { utils_1 as utils };
|
|
5
6
|
export { SignatureAlgorithm, HashType, Network, } from './interfaces';
|
|
6
7
|
export * from './Errors';
|
|
7
8
|
export * from './network';
|
|
@@ -26,16 +26,16 @@ interface ListUnspentItem {
|
|
|
26
26
|
}
|
|
27
27
|
interface RpcClientRetry {
|
|
28
28
|
constructor(url: string, opts?: object): void;
|
|
29
|
-
listUnspent(
|
|
29
|
+
listUnspent(minConf?: number, maxConf?: number, addresses?: string[], includeUnsafe?: boolean, queryOptions?: object): Promise<ListUnspentItem[]>;
|
|
30
30
|
getBlockCount(): Promise<number>;
|
|
31
|
-
getRawTransaction(txid: string, verbose?: boolean,
|
|
32
|
-
sendRawTransaction(
|
|
33
|
-
generate(
|
|
34
|
-
generateToAddress(
|
|
31
|
+
getRawTransaction(txid: string, verbose?: boolean, blockHash?: string): Promise<string>;
|
|
32
|
+
sendRawTransaction(hexString: string, allowHighFees?: boolean): Promise<string>;
|
|
33
|
+
generate(nBlocks: number, maxTries?: number): Promise<string[]>;
|
|
34
|
+
generateToAddress(nBlocks: number, address: string, maxTries?: number): Promise<string[]>;
|
|
35
35
|
getNewAddress(label?: string): Promise<string>;
|
|
36
36
|
dumpPrivKey(address: string): Promise<string>;
|
|
37
|
-
getBalance(dummy?: string,
|
|
38
|
-
getBlock(
|
|
37
|
+
getBalance(dummy?: string, minConf?: number, includeWatchOnly?: boolean): Promise<number>;
|
|
38
|
+
getBlock(blockHash: string, verbosity?: number): Promise<string>;
|
|
39
39
|
importAddress(address: string, label?: string, rescan?: boolean, p2sh?: boolean): Promise<void>;
|
|
40
40
|
}
|
|
41
41
|
export {};
|
|
@@ -35,12 +35,16 @@ export default class ElectrumNetworkProvider {
|
|
|
35
35
|
}
|
|
36
36
|
else if (network === Network.TESTNET) {
|
|
37
37
|
// Initialise a 1-of-2 Electrum Cluster with 2 hardcoded servers
|
|
38
|
-
this.electrum = new ElectrumCluster('CashScript Application', '1.4.1', 1, 2);
|
|
38
|
+
this.electrum = new ElectrumCluster('CashScript Application', '1.4.1', 1, 2, ClusterOrder.PRIORITY);
|
|
39
39
|
this.electrum.addServer('blackie.c3-soft.com', 60004, ElectrumTransport.WSS.Scheme, false);
|
|
40
40
|
this.electrum.addServer('electroncash.de', 60004, ElectrumTransport.WSS.Scheme, false);
|
|
41
41
|
// this.electrum.addServer('bch.loping.net', 60004, ElectrumTransport.WSS.Scheme, false);
|
|
42
42
|
// this.electrum.addServer('testnet.imaginary.cash', 50004, ElectrumTransport.WSS.Scheme);
|
|
43
43
|
}
|
|
44
|
+
else if (network === Network.STAGING) {
|
|
45
|
+
this.electrum = new ElectrumCluster('CashScript Application', '1.4.1', 1, 1, ClusterOrder.PRIORITY);
|
|
46
|
+
this.electrum.addServer('testnet4.imaginary.cash', 50004, ElectrumTransport.WSS.Scheme, false);
|
|
47
|
+
}
|
|
44
48
|
else {
|
|
45
49
|
throw new Error(`Tried to instantiate an ElectrumNetworkProvider for unsupported network ${network}`);
|
|
46
50
|
}
|
package/dist/module/utils.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Transaction } from '@bitauth/libauth';
|
|
2
2
|
import { Script } from '@cashscript/utils';
|
|
3
|
-
import { Utxo, Output } from './interfaces';
|
|
3
|
+
import { Utxo, Output, Recipient } from './interfaces';
|
|
4
4
|
import { FailedTransactionError } from './Errors';
|
|
5
|
+
export declare function validateRecipient(recipient: Recipient): void;
|
|
5
6
|
export declare function getInputSize(inputScript: Uint8Array): number;
|
|
6
7
|
export declare function getPreimageSize(script: Uint8Array): number;
|
|
7
8
|
export declare function getTxSizeWithoutInputs(outputs: Output[]): number;
|
package/dist/module/utils.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { cashAddressToLockingBytecode, AddressType, addressContentsToLockingBytecode, lockingBytecodeToCashAddress, binToHex, createTransactionContextCommon, bigIntToBinUint64LE, generateSigningSerializationBCH, utf8ToBin, hexToBin, flattenBinArray, } from '@bitauth/libauth';
|
|
2
2
|
import { encodeInt, hash160, Op, scriptToBytecode, sha256, } from '@cashscript/utils';
|
|
3
|
-
import { Network } from './interfaces';
|
|
4
|
-
import { P2PKH_OUTPUT_SIZE, VERSION_SIZE, LOCKTIME_SIZE } from './constants';
|
|
5
|
-
import { Reason, FailedTransactionError, FailedRequireError, FailedTimeCheckError, FailedSigCheckError, } from './Errors';
|
|
3
|
+
import { Network, } from './interfaces';
|
|
4
|
+
import { P2PKH_OUTPUT_SIZE, VERSION_SIZE, LOCKTIME_SIZE, DUST_LIMIT, } from './constants';
|
|
5
|
+
import { OutputSatoshisTooSmallError, Reason, FailedTransactionError, FailedRequireError, FailedTimeCheckError, FailedSigCheckError, } from './Errors';
|
|
6
|
+
// ////////// PARAMETER VALIDATION ////////////////////////////////////////////
|
|
7
|
+
export function validateRecipient(recipient) {
|
|
8
|
+
if (recipient.amount < DUST_LIMIT) {
|
|
9
|
+
throw new OutputSatoshisTooSmallError(recipient.amount);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
6
12
|
// ////////// SIZE CALCULATIONS ///////////////////////////////////////////////
|
|
7
13
|
export function getInputSize(inputScript) {
|
|
8
14
|
const scriptSize = inputScript.byteLength;
|
|
@@ -147,6 +153,8 @@ export function getNetworkPrefix(network) {
|
|
|
147
153
|
switch (network) {
|
|
148
154
|
case Network.MAINNET:
|
|
149
155
|
return 'bitcoincash';
|
|
156
|
+
case Network.STAGING:
|
|
157
|
+
return 'bchtest';
|
|
150
158
|
case Network.TESTNET:
|
|
151
159
|
return 'bchtest';
|
|
152
160
|
case Network.REGTEST:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cashscript",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0-next.0",
|
|
4
4
|
"description": "Easily write and interact with Bitcoin Cash contracts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bitcoin cash",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@bitauth/libauth": "^1.18.1",
|
|
45
|
-
"@cashscript/utils": "^0.
|
|
45
|
+
"@cashscript/utils": "^0.7.0-next.0",
|
|
46
46
|
"bip68": "^1.0.4",
|
|
47
47
|
"bitcoin-rpc-promise-retry": "^1.3.0",
|
|
48
48
|
"delay": "^5.0.0",
|