Browse Source

blockchain/header: Reorder the header so nonce is before timestamp

x 7 tháng trước cách đây
mục cha
commit
0d12199568
1 tập tin đã thay đổi với 11 bổ sung2 xóa
  1. 11 2
      src/blockchain/header_store.rs

+ 11 - 2
src/blockchain/header_store.rs

@@ -94,10 +94,10 @@ pub struct Header {
     pub previous: HeaderHash,
     /// Block height
     pub height: u32,
-    /// Block creation timestamp
-    pub timestamp: Timestamp,
     /// The block's nonce. This value changes arbitrarily with mining.
     pub nonce: u32,
+    /// Block creation timestamp
+    pub timestamp: Timestamp,
     /// Merkle tree root of the transactions hashes contained in this block
     pub transactions_root: MerkleNode,
     /// Contracts states Monotree(SMT) root this block commits to
@@ -178,6 +178,15 @@ impl Header {
             }
         }
     }
+
+    /// Create a blockhashing blob from this header
+    pub fn to_blockhashing_blob(&self) -> Vec<u8> {
+        // For XMRig, we need to pad the blob so that our nonce ends
+        // up at byte offset 39.
+        let mut blob = vec![0x00, 0x00];
+        blob.extend_from_slice(&serialize(self));
+        blob
+    }
 }
 
 impl Default for Header {