Skip to content

Commit

Permalink
Make static variables immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewLM committed Sep 7, 2023
1 parent e522d46 commit b1c35e2
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 32 deletions.
6 changes: 3 additions & 3 deletions coinlib/lib/src/crypto/hd_key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class InvalidHDKeyVersion implements Exception {}

abstract class HDKey {

static int maxIndex = 0xffffffff;
static int hardenBit = 0x80000000;
static int encodedLength = 78;
static const maxIndex = 0xffffffff;
static const hardenBit = 0x80000000;
static const encodedLength = 78;

final Uint8List _chaincode;
final int depth;
Expand Down
8 changes: 4 additions & 4 deletions coinlib/lib/src/encode/bech32.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ enum Bech32Type { bech32, bech32m }
/// words may need to be further converted into the required data.
class Bech32 {

static int maxLength = 90;
static int checksumLength = 6;
static int bech32CheckConst = 1;
static int bech32mCheckConst = 0x2bc830a3;
static const maxLength = 90;
static const checksumLength = 6;
static const bech32CheckConst = 1;
static const bech32mCheckConst = 0x2bc830a3;

final String hrp;
final List<int> words;
Expand Down
13 changes: 6 additions & 7 deletions coinlib/lib/src/scripts/operations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ class PushDataNotMinimal implements Exception {}
/// Represents a single operation or script pushdata
abstract class ScriptOp {

static int op1Negate = scriptOpNameToCode["1NEGATE"]!;
static int op1 = scriptOpNameToCode["1"]!;
static int op16 = scriptOpNameToCode["16"]!;
static int pushData1 = scriptOpNameToCode["PUSHDATA1"]!;
static int pushData2 = pushData1+1;
static int pushData4 = pushData2+1;

static final op1Negate = scriptOpNameToCode["1NEGATE"]!;
static final op1 = scriptOpNameToCode["1"]!;
static final op16 = scriptOpNameToCode["16"]!;
static final pushData1 = scriptOpNameToCode["PUSHDATA1"]!;
static final pushData2 = pushData1+1;
static final pushData4 = pushData2+1;
static final pushdataMatcherRegExp = RegExp(r"^<(\d+)-bytes>$");

/// The compiled bytes for this operation
Expand Down
4 changes: 2 additions & 2 deletions coinlib/lib/src/scripts/programs/multisig.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import 'package:coinlib/src/scripts/script.dart';

class MultisigProgram implements Program {

static int maxPubkeys = 20;
static ScriptOp checkmultisig = ScriptOpCode.fromName("CHECKMULTISIG");
static const maxPubkeys = 20;
static final checkmultisig = ScriptOpCode.fromName("CHECKMULTISIG");

@override
final Script script;
Expand Down
2 changes: 1 addition & 1 deletion coinlib/lib/src/scripts/programs/p2pkh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:coinlib/src/scripts/script.dart';
/// satisfy this script with a signature.
class P2PKH implements Program {

static Script template = Script.fromAsm(
static final template = Script.fromAsm(
"OP_DUP OP_HASH160 <20-bytes> OP_EQUALVERIFY OP_CHECKSIG",
);

Expand Down
2 changes: 1 addition & 1 deletion coinlib/lib/src/scripts/programs/p2sh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:coinlib/src/scripts/script.dart';
/// Pay-to-Script-Hash program taking a 20-byte script hash for a redeem script.
class P2SH implements Program {

static Script template = Script.fromAsm("OP_HASH160 <20-bytes> OP_EQUAL");
static final template = Script.fromAsm("OP_HASH160 <20-bytes> OP_EQUAL");

@override
final Script script;
Expand Down
2 changes: 1 addition & 1 deletion coinlib/lib/src/tx/output.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:coinlib/src/scripts/script.dart';
class Output with Writable {

/// Max 64-bit integer
static BigInt maxValue = (BigInt.from(1) << 64) - BigInt.one;
static final maxValue = (BigInt.from(1) << 64) - BigInt.one;

final BigInt value;
final Uint8List _scriptPubKey;
Expand Down
8 changes: 4 additions & 4 deletions coinlib/lib/src/tx/sighash_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
class SigHashType {

/// Value to sign all outputs
static const int allValue = 1;
static const allValue = 1;
/// Value to sign no outputs
static const int noneValue = 2;
static const noneValue = 2;
/// Value to sign the output at the same index as the input
static const int singleValue = 3;
static const singleValue = 3;
/// Flag that can be combined with other hash type values to only sign the
/// input containing the signature
static const int anyOneCanPayFlag = 0x80;
static const anyOneCanPayFlag = 0x80;

/// The single byte representation of the sighash type. Use [all], [none],
/// [single] and [anyonecanpay] to extract details of the type.
Expand Down
18 changes: 9 additions & 9 deletions coinlib/lib/src/tx/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ class CannotSignInput implements Exception {
/// with witness data.
class Transaction with Writable {

static Uint8List hashZero = Uint8List(32);
static Uint8List hashOne = Uint8List(32)..last = 1;
static final hashZero = Uint8List(32);
static final hashOne = Uint8List(32)..last = 1;

static const int currentVersion = 3;
static const int maxSize = 1000000;
static const currentVersion = 3;
static const maxSize = 1000000;

static const int minInputSize = 41;
static const int minOutputSize = 9;
static const int minOtherSize = 10;
static const minInputSize = 41;
static const minOutputSize = 9;
static const minOtherSize = 10;

static const int maxInputs
static const maxInputs
= (maxSize - minOtherSize - minOutputSize) ~/ minInputSize;
static const int maxOutputs
static const maxOutputs
= (maxSize - minOtherSize - minInputSize) ~/ minOutputSize;

final int version;
Expand Down

0 comments on commit b1c35e2

Please sign in to comment.