wire: little cleanup
This commit is contained in:
parent
7b628a2a88
commit
755c0b0188
@ -37,31 +37,20 @@ func (p *BitcoinBlockParser) parseOutputScript(b []byte) ([]string, error) {
|
|||||||
func (p *BitcoinBlockParser) ParseBlock(b []byte) (*Block, error) {
|
func (p *BitcoinBlockParser) ParseBlock(b []byte) (*Block, error) {
|
||||||
w := wire.MsgBlock{}
|
w := wire.MsgBlock{}
|
||||||
r := bytes.NewReader(b)
|
r := bytes.NewReader(b)
|
||||||
if err := w.DeserializeNoWitness(r); err != nil {
|
|
||||||
|
if err := w.Deserialize(r); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
block := &Block{
|
txs := make([]Tx, len(w.Transactions))
|
||||||
Txs: make([]*Tx, len(w.Transactions)),
|
|
||||||
}
|
|
||||||
for ti, t := range w.Transactions {
|
for ti, t := range w.Transactions {
|
||||||
tx := &Tx{
|
vin := make([]Vin, len(t.TxIn))
|
||||||
Txid: t.TxHash().String(),
|
|
||||||
Version: t.Version,
|
|
||||||
LockTime: t.LockTime,
|
|
||||||
Vin: make([]Vin, len(t.TxIn)),
|
|
||||||
Vout: make([]Vout, len(t.TxOut)),
|
|
||||||
// missing: BlockHash,
|
|
||||||
// missing: Confirmations,
|
|
||||||
// missing: Time,
|
|
||||||
// missing: Blocktime,
|
|
||||||
}
|
|
||||||
for i, in := range t.TxIn {
|
for i, in := range t.TxIn {
|
||||||
s := ScriptSig{
|
s := ScriptSig{
|
||||||
Hex: hex.EncodeToString(in.SignatureScript),
|
Hex: hex.EncodeToString(in.SignatureScript),
|
||||||
// missing: Asm,
|
// missing: Asm,
|
||||||
}
|
}
|
||||||
tx.Vin[i] = Vin{
|
vin[i] = Vin{
|
||||||
Coinbase: "_",
|
Coinbase: "_",
|
||||||
Txid: in.PreviousOutPoint.Hash.String(),
|
Txid: in.PreviousOutPoint.Hash.String(),
|
||||||
Vout: in.PreviousOutPoint.Index,
|
Vout: in.PreviousOutPoint.Index,
|
||||||
@ -69,6 +58,7 @@ func (p *BitcoinBlockParser) ParseBlock(b []byte) (*Block, error) {
|
|||||||
ScriptSig: s,
|
ScriptSig: s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
vout := make([]Vout, len(t.TxOut))
|
||||||
for i, out := range t.TxOut {
|
for i, out := range t.TxOut {
|
||||||
addrs, err := p.parseOutputScript(out.PkScript)
|
addrs, err := p.parseOutputScript(out.PkScript)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -80,14 +70,24 @@ func (p *BitcoinBlockParser) ParseBlock(b []byte) (*Block, error) {
|
|||||||
// missing: Asm,
|
// missing: Asm,
|
||||||
// missing: Type,
|
// missing: Type,
|
||||||
}
|
}
|
||||||
tx.Vout[i] = Vout{
|
vout[i] = Vout{
|
||||||
Value: float64(out.Value),
|
Value: float64(out.Value),
|
||||||
N: uint32(i),
|
N: uint32(i),
|
||||||
ScriptPubKey: s,
|
ScriptPubKey: s,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
block.Txs[ti] = tx
|
txs[ti] = Tx{
|
||||||
|
Txid: t.TxHash().String(),
|
||||||
|
Version: t.Version,
|
||||||
|
LockTime: t.LockTime,
|
||||||
|
Vin: vin,
|
||||||
|
Vout: vout,
|
||||||
|
// missing: BlockHash,
|
||||||
|
// missing: Confirmations,
|
||||||
|
// missing: Time,
|
||||||
|
// missing: Blocktime,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return block, nil
|
return &Block{Txs: txs}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user