-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
706 additions
and
585 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
const DIFFICULTY = | ||
export const DIFFICULTY = | ||
"0000ffff00000000000000000000000000000000000000000000000000000000"; | ||
|
||
export const WITNESS_RESERVED_VALUE = | ||
"0000000000000000000000000000000000000000000000000000000000000000"; | ||
|
||
export const MAX_VALUE = 0xffffffff; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,48 @@ | ||
import { Transaction } from "../../types"; | ||
// import { Transaction } from "../../types"; | ||
import { MAX_VALUE, WITNESS_RESERVED_VALUE } from "../../constants"; | ||
import { compactSize } from "../encoding/compactSize"; | ||
import { Input, Output, Transaction } from "../transaction"; | ||
|
||
export const ZEROS = | ||
"0000000000000000000000000000000000000000000000000000000000000000"; | ||
const MAX_VALUE = 0xffffffff; | ||
const height = 538403; | ||
// export const ZEROS = | ||
// "0000000000000000000000000000000000000000000000000000000000000000"; | ||
// const MAX_VALUE = 0xffffffff; | ||
// const height = 538403; | ||
const blockReward = 1250000000; | ||
|
||
const coinbaseTemplate = { | ||
version: 0, | ||
locktime: 0, | ||
vin: [ | ||
{ | ||
txid: ZEROS, | ||
vout: MAX_VALUE, | ||
prevout: null, | ||
scriptsig: "03233708", | ||
scriptsig_asm: "OP_PUSHBYTES_3 233708", | ||
witness: [ZEROS], | ||
}, | ||
], | ||
vout: [ | ||
{ | ||
scriptpubkey: "76a914edf10a7fac6b32e24daa5305c723f3de58db1bc888ac", | ||
scriptpubkey_asm: | ||
"OP_DUP OP_HASH160 OP_PUSHBYTES_20 edf10a7fac6b32e24daa5305c723f3de58db1bc8 OP_EQUALVERIFY OP_CHECKSIG", | ||
scriptpubkey_type: "p2pkh", | ||
value: blockReward, | ||
}, | ||
{ | ||
//op return push 36 bytes 4 btyes commitment + hash256 of witness merkle root + zeros | ||
scriptpubkey: "6a24aa21a9ed", // add the witness commitment later | ||
scriptpubkey_type: "op_return", | ||
value: 0, | ||
}, | ||
], | ||
} as unknown as Transaction; | ||
|
||
export const generateCoinbaseTransaction = ( | ||
totalFee: number, | ||
commitmentHeader: string | ||
) => { | ||
coinbaseTemplate.vout[1].scriptpubkey = `6a24aa21a9ed${commitmentHeader}`; | ||
coinbaseTemplate.vout[0].value = blockReward + totalFee; | ||
const transaction = new Transaction(0, 0); | ||
const input = new Input({ | ||
txid: WITNESS_RESERVED_VALUE, | ||
vout: MAX_VALUE, | ||
prevout: null, | ||
scriptsig: "03233708", //block number is 233708 | ||
scriptsig_asm: "OP_PUSHBYTES_3 233708", | ||
witness: [WITNESS_RESERVED_VALUE], | ||
sequence: 0, | ||
is_coinbase: true, | ||
}); | ||
|
||
const output1 = new Output({ | ||
scriptpubkey: "76a914edf10a7fac6b32e24daa5305c723f3de58db1bc888ac", | ||
scriptpubkey_asm: | ||
"OP_DUP OP_HASH160 OP_PUSHBYTES_20 edf10a7fac6b32e24daa5305c723f3de58db1bc8 OP_EQUALVERIFY OP_CHECKSIG", | ||
scriptpubkey_type: "p2pkh", | ||
value: blockReward + totalFee, | ||
}); | ||
|
||
const output2 = new Output({ | ||
scriptpubkey: "6a24aa21a9ed" + commitmentHeader, | ||
scriptpubkey_asm: "OP_RETURN OP_PUSHBYTES_36 aa21a9ed" + commitmentHeader, | ||
scriptpubkey_type: "op_return", | ||
value: 0, | ||
}); | ||
|
||
transaction.addInput(input); | ||
transaction.addOutput(output1); | ||
transaction.addOutput(output2); | ||
|
||
return coinbaseTemplate; | ||
return transaction; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.