-
Notifications
You must be signed in to change notification settings - Fork 6
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
Jonas Rudloff
committed
Jul 22, 2011
1 parent
8f8e580
commit f3c3f98
Showing
20 changed files
with
486 additions
and
2,702 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
Peter Davies <[email protected]> | ||
Jonas Rudloff <pcfreck "AT" gmail "DOT" com> |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from utils import * | ||
import genesisblock | ||
import msgs | ||
import jserialize as js | ||
import bserialize as bs | ||
class BlockAux(js.Entity, bs.Entity): | ||
fields = { | ||
"block":msgs.Block, | ||
"txs":js.List(js.Hash), | ||
"number":js.Int, | ||
"totaldiff":js.Int, | ||
"succ": js.Hash, | ||
} | ||
bfields = [ | ||
("block", msgs.Block), | ||
("txs", bs.VarList(bs.Hash)), | ||
("number", bs.structfmt("<Q")), | ||
("totaldiff", bs.structfmt("<Q")), | ||
("succ", bs.Hash), | ||
] | ||
@property | ||
def hash(self): | ||
return self.block.hash | ||
@constructor | ||
def make(self, blockmsg): | ||
self.block, self.txs, self.number = blockmsg.block, [tx.hash for tx in blockmsg.txs], 2**64-1 | ||
self.totaldiff = 0 | ||
self.succ = nullhash | ||
|
||
class BlockList(js.Entity, bs.Entity): | ||
fields = { | ||
"blocks":js.List(js.Hash), | ||
} | ||
bfields = [ | ||
("blocks", bs.VarList(bs.Hash)), | ||
] | ||
class BlockChain: | ||
def __init__(self, db, server, txdb): | ||
self._db | ||
self.server = server | ||
self.txdb = txdb | ||
try: | ||
self.mainchain = self._db["mainchain"] | ||
except: | ||
self.add(genesisblock.blockmsg) | ||
def put_aux(aux): | ||
self._db[aux.hash] = aux.tobinary() | ||
|
||
def add(self, blockmsg): | ||
if blockmsg.block.hash in self._db: | ||
return | ||
aux = BlockAux.make(blockmsg) | ||
if blockmsg.block.prev == nullhash: | ||
aux.number = 1 | ||
aux.totaldiff = bits_to_diff(aux.block.bits) | ||
self.put_aux(aux) | ||
|
||
|
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 +1,6 @@ | ||
blockmsg = {"type": "block", "txs": [{"inputs": [{"script": "04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73", "outpoint": {"index": 4294967295, "tx": "0000000000000000000000000000000000000000000000000000000000000000"}, "sequence": 4294967295}], "locktime": 0, "version": 1, "outputs": [{"amount": 5000000000, "script": "4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac"}]}], "block": {"nonce": 2083236893, "version": 1, "time": 1231006505, "merkle": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b", "bits": 0x1d00ffff, "prev": "0000000000000000000000000000000000000000000000000000000000000000"}} | ||
import msgs | ||
blockmsg = msgs.Blockmsg.fromjson({"type": "block", "txs": [{"inputs": [{"script": "04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73", "outpoint": {"index": 4294967295, "tx": "0000000000000000000000000000000000000000000000000000000000000000"}, "sequence": 4294967295}], "locktime": 0, "version": 1, "outputs": [{"amount": 5000000000, "script": "4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac"}]}], "block": {"nonce": 2083236893, "version": 1, "time": 1231006505, "merkle": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b", "bits": 0x1d00ffff, "prev": "0000000000000000000000000000000000000000000000000000000000000000"}}) | ||
block = blockmsg.block | ||
hash = block.hash | ||
|
||
|
Oops, something went wrong.