fix errors
parent
03f910cc30
commit
4dc5721384
|
@ -60,3 +60,86 @@ func GetChainParams(chain string) *chaincfg.Params {
|
|||
return &MainNetParams
|
||||
}
|
||||
}
|
||||
|
||||
func parseBlockHeader(r io.Reader) (*wire.BlockHeader, error) {
|
||||
h := &wire.BlockHeader{}
|
||||
err := h.Deserialize(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// hash_state_root 32
|
||||
// hash_utxo_root 32
|
||||
// hash_prevout_stake 32
|
||||
// hash_prevout_n 4
|
||||
buf := make([]byte, 100)
|
||||
_, err = io.ReadFull(r, buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sigLength, err := wire.ReadVarInt(r, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sigBuf := make([]byte, sigLength)
|
||||
_, err = io.ReadFull(r, sigBuf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return h, err
|
||||
}
|
||||
|
||||
func (p *VIPSTARCOINParser) ParseBlock(b []byte) (*bchain.Block, error) {
|
||||
r := bytes.NewReader(b)
|
||||
w := wire.MsgBlock{}
|
||||
|
||||
h, err := parseBlockHeader(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = utils.DecodeTransactions(r, 0, wire.WitnessEncoding, &w)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
txs := make([]bchain.Tx, len(w.Transactions))
|
||||
for ti, t := range w.Transactions {
|
||||
txs[ti] = p.TxFromMsgTx(t, false)
|
||||
}
|
||||
|
||||
return &bchain.Block{
|
||||
BlockHeader: bchain.BlockHeader{
|
||||
Size: len(b),
|
||||
Time: h.Timestamp.Unix(),
|
||||
},
|
||||
Txs: txs,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ParseTxFromJson parses JSON message containing transaction and returns Tx struct
|
||||
func (p *VIPSTARCOINParser) ParseTxFromJson(msg json.RawMessage) (*bchain.Tx, error) {
|
||||
var tx bchain.Tx
|
||||
err := json.Unmarshal(msg, &tx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for i := range tx.Vout {
|
||||
vout := &tx.Vout[i]
|
||||
// convert vout.JsonValue to big.Int and clear it, it is only temporary value used for unmarshal
|
||||
vout.ValueSat, err = p.AmountToBigInt(vout.JsonValue)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
vout.JsonValue = ""
|
||||
|
||||
if vout.ScriptPubKey.Addresses == nil {
|
||||
vout.ScriptPubKey.Addresses = []string{}
|
||||
}
|
||||
}
|
||||
|
||||
return &tx, nil
|
||||
}
|
||||
|
|
|
@ -23,8 +23,8 @@ func NewVIPSTARCOINRPC(config json.RawMessage, pushHandler func(bchain.Notificat
|
|||
s := &VIPSTARCOINRPC{
|
||||
b.(*btc.BitcoinRPC),
|
||||
}
|
||||
s.RPCMarshaler = btc.JSONMarshalerV2{}
|
||||
s.ChainConfig.SupportsEstimateFee = false
|
||||
s.RPCMarshaler = btc.JSONMarshalerV1{}
|
||||
s.ChainConfig.SupportsEstimateSmartFee = true
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
@ -56,3 +56,9 @@ func (b *VIPSTARCOINRPC) Initialize() error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetTransactionForMempool returns a transaction by the transaction ID
|
||||
// It could be optimized for mempool, i.e. without block time and confirmations
|
||||
func (b *VIPSTARCOINRPC) GetTransactionForMempool(txid string) (*bchain.Tx, error) {
|
||||
return b.GetTransaction(txid)
|
||||
}
|
||||
|
|
|
@ -26,9 +26,9 @@
|
|||
"binary_url": "https://github.com/y-chan/VIPSTARCOIN/releases/download/v1.0.2/VIPSTARCOIN-1.0.2-x86_64-linux-gnu.tar.gz",
|
||||
"verification_type": "sha256",
|
||||
"verification_source": "0bb608cf9103a896f2c1bf7f189db78f717019c2cc622f36581129876c65f131",
|
||||
"extract_command": "tar -C backend --strip 1 -xf",
|
||||
"extract_command": "tar -C backend --strip 1 -xzvf",
|
||||
"exclude_files": [
|
||||
"bin/VIPSTARCOIN-qt"
|
||||
"VIPSTARCOIN-qt"
|
||||
],
|
||||
"exec_command_template": "{{.Env.BackendInstallPath}}/{{.Coin.Alias}}/VIPSTARCOINd -datadir={{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend -conf={{.Env.BackendInstallPath}}/{{.Coin.Alias}}/{{.Coin.Alias}}.conf -pid=/run/{{.Coin.Alias}}/{{.Coin.Alias}}.pid",
|
||||
"logrotate_files_template": "{{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend/*.log",
|
||||
|
|
Loading…
Reference in New Issue