-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathboost.go
89 lines (83 loc) · 4.13 KB
/
boost.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package boost
// Prefix is the protocol prefix for Boost Pow
const Prefix = "boostpow"
// Boost is Boost Pow data object
type Boost struct {
Redeem Redeem `json:"redeem" bson:"redeem"`
Spend Spend `json:"spend" bson:"spend"`
}
// Spend is the parsed spend data. Version unknown when 0.
type Spend struct {
Hash string `json:"hash,omitempty" bson:"hash,omitempty"`
Content string `json:"content,omitempty" bson:"content,omitempty"`
Difficulty float64 `json:"difficulty,omitempty" bson:"difficulty,omitempty"`
Topic *string `json:"topic,omitempty" bson:"topic,omitempty"`
AdditionalData *string `json:"additional_data,omitempty" bson:"additional_data,omitempty"`
Bits uint64 `json:"bits" bson:"bits"`
MetadataHash string `json:"metadata_hash,omitempty" bson:"metadata_hash,omitempty"`
Time uint64 `json:"time,omitempty" bson:"time,omitempty"`
Nonce uint32 `json:"nonce,omitempty" bson:"nonce,omitempty"`
Category uint32 `json:"category" bson:"category,omitempty"`
MinerAddress *string `json:"miner_address,omitempty" bson:"miner_address,omitempty"`
Version int32 `json:"version" bson:"version"`
}
// Redeem is the parsed redeem data
type Redeem struct {
// 3044022100ac4003d62ddadbf0bff9cbe63d0f6ad740494ee7fcf5f296cfc056f52f087c7c\
// 021f2f9e2db03b141ce88edc1c10850a0831dea63edd6c6a8040d80e24737e6d4a41
Signature string `json:"signature" bson:"signature"`
// pubkey: 03097e9768554d40c0b5b18e44db2a15bbd137a373c39af46033049477bcbb79a4
PubKey string `json:"pubkey" bson:"pubkey"`
// nonce : 31497
Nonce uint32 `json:"nonce" bson:"nonce"`
// timestamp : 1677268580
Timestamp uint32 `json:"timestamp" bson:"timestamp"`
// extra_nonce_2 : "0f0445b186e64adc"
ExtraNonce2 string `json:"extra_nonce_2" bson:"extra_nonce_2"`
// extra_nonce_1 : 909479219
ExtraNonce1 uint32 `json:"extra_nonce_1" bson:"extra_nonce_1"`
// miner_pubkey_hash: 0xa3c10ac097a7da0009a786cc17edc1391a3bddf6
MinerPubKeyHash string `json:"miner_pubkey_hash" bson:"miner_pubkey_hash"`
Version int32 `json:"version" bson:"version"`
}
// pattern output_script_pattern_no_asicboost = pattern{
// 0 - push{bytes{0x62, 0x6F, 0x6F, 0x73, 0x74, 0x70, 0x6F, 0x77}},
// 1 - OP_DROP,
// 2 - optional{push_size{20, MinerAddress}},
// 2, 3 - push_size{4, Category},
// 3, 4 - push_size{32, Content},
// 4, 5 - push_size{4, Target},
// 5, 6 - push{x.Tag},
// 6, 7 - push_size{4, UserNonce},
// push{x.AdditionalData}, OP_CAT, OP_SWAP,
// // copy mining pool’s pubkey hash to alt stack. A copy remains on the stack.
// push{5}, OP_ROLL, OP_DUP, OP_TOALTSTACK, OP_CAT,
// // copy target and push to altstack.
// push{2}, OP_PICK, OP_TOALTSTACK,
// // check size of extra_nonce_1
// push{5}, OP_ROLL, OP_SIZE, push{4}, OP_EQUALVERIFY, OP_CAT,
// // check size of extra_nonce_2
// push{5}, OP_ROLL, OP_SIZE, push{8}, OP_EQUALVERIFY, OP_CAT,
// // create metadata document and hash it.
// OP_SWAP, OP_CAT, OP_HASH256,
// OP_SWAP, OP_TOALTSTACK, OP_CAT, OP_CAT, // target to altstack.
// OP_SWAP, OP_SIZE, push{4}, OP_EQUALVERIFY, OP_CAT, // check size of timestamp.
// OP_FROMALTSTACK, OP_CAT, // attach target
// // check size of nonce. Boost POW string is constructed.
// OP_SWAP, OP_SIZE, push{4}, OP_EQUALVERIFY, OP_CAT,
// // Take hash of work string and ensure that it is positive and minimally encoded.
// OP_HASH256, ensure_positive,
// // Get target, transform to expanded form, and ensure that it is positive and minimally encoded.
// OP_FROMALTSTACK, expand_target, ensure_positive,
// // check that the hash of the Boost POW string is less than the target
// OP_LESSTHAN, OP_VERIFY,
// // check that the given address matches the pubkey and check signature.
// OP_DUP, OP_HASH160, OP_FROMALTSTACK, OP_EQUALVERIFY, OP_CHECKSIG};
// hash: '0000000086915e291fe43f10bdd8232f65e6eb64628bbb4d128be3836c21b6cc',
// content: '00000000000000000000000000000000000000000048656c6c6f20776f726c64',
// bits: 486604799,
// difficulty: 1,
// metadataHash: "acd8278e84b037c47565df65a981d72fb09be5262e8783d4cf4e42633615962a",
// time: 1305200806,
// nonce: 3698479534,
// category: 1,