Skip to content
Permalink
Browse files

revert

  • Loading branch information...
eabz committed Oct 12, 2019
1 parent 17677ac commit fdfb07b07658fa3cd37434826008c6bb86fc2220

Some generated files are not rendered by default. Learn more.

@@ -6,6 +6,7 @@ import (
"blockbook/bchain/coins/bellcoin"
"blockbook/bchain/coins/btc"
"blockbook/bchain/coins/btg"
"blockbook/bchain/coins/cpuchain"
"blockbook/bchain/coins/dash"
"blockbook/bchain/coins/dcr"
"blockbook/bchain/coins/digibyte"
@@ -29,6 +30,8 @@ import (
"blockbook/bchain/coins/qtum"
"blockbook/bchain/coins/ravencoin"
"blockbook/bchain/coins/ritocoin"
"blockbook/bchain/coins/telos"
"blockbook/bchain/coins/unobtanium"
"blockbook/bchain/coins/vertcoin"
"blockbook/bchain/coins/viacoin"
"blockbook/bchain/coins/vipstarcoin"
@@ -99,6 +102,9 @@ func init() {
BlockChainFactories["Ravencoin"] = ravencoin.NewRavencoinRPC
BlockChainFactories["Ritocoin"] = ritocoin.NewRitocoinRPC
BlockChainFactories["Divi"] = divi.NewDiviRPC
BlockChainFactories["CPUchain"] = cpuchain.NewCPUchainRPC
BlockChainFactories["Unobtanium"] = unobtanium.NewUnobtaniumRPC
BlockChainFactories["Telos"] = telos.NewTelosRPC
}

// GetCoinNameFromConfig gets coin name and coin shortcut from config file
@@ -172,6 +172,7 @@ func (p *DecredParser) ParseTxFromJson(jsonTx json.RawMessage) (*bchain.Tx, erro
Txid: getTxResult.Result.Txid,
Version: getTxResult.Result.Version,
LockTime: getTxResult.Result.LockTime,
BlockHeight: getTxResult.Result.BlockHeight,
Vin: vins,
Vout: vouts,
Confirmations: uint32(getTxResult.Result.Confirmations),
@@ -2,14 +2,15 @@ package eth

import (
"blockbook/bchain"
"bytes"
"context"
"encoding/hex"
"math/big"
"strings"
"sync"
"unicode/utf8"

ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/golang/glog"
"github.com/juju/errors"
)
@@ -151,6 +152,18 @@ func parseErc20StringProperty(contractDesc bchain.AddressDescriptor, data string
}
}
}
} else if len(data) == 64 {
// allow string properties as 32 bytes of UTF-8 data
b, err := hex.DecodeString(data)
if err == nil {
i := bytes.Index(b, []byte{0})
if i > 0 {
b = b[:i]
}
if utf8.Valid(b) {
return string(b)
}
}
}
if glog.V(1) {
glog.Warning("Cannot parse '", data, "' for contract ", contractDesc)
@@ -165,7 +178,7 @@ func (b *EthereumRPC) EthereumTypeGetErc20ContractInfo(contractDesc bchain.Addre
contract, found := cachedContracts[cds]
cachedContractsMux.Unlock()
if !found {
address := hexutil.Encode(contractDesc)
address := EIP55Address(contractDesc)
data, err := b.ethCall(erc20NameSignature, address)
if err != nil {
return nil, err
@@ -204,8 +217,8 @@ func (b *EthereumRPC) EthereumTypeGetErc20ContractInfo(contractDesc bchain.Addre

// EthereumTypeGetErc20ContractBalance returns balance of ERC20 contract for given address
func (b *EthereumRPC) EthereumTypeGetErc20ContractBalance(addrDesc, contractDesc bchain.AddressDescriptor) (*big.Int, error) {
addr := hexutil.Encode(addrDesc)
contract := hexutil.Encode(contractDesc)
addr := EIP55Address(addrDesc)
contract := EIP55Address(contractDesc)
req := erc20BalanceOf + "0000000000000000000000000000000000000000000000000000000000000000"[len(addr)-2:] + addr[2:]
data, err := b.ethCall(req, contract)
if err != nil {
@@ -128,6 +128,16 @@ func TestErc20_parseErc20StringProperty(t *testing.T) {
args: "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000022426974436c617665202d20436f6e73756d657220416374697669747920546f6b656e00000000000000",
want: "BitClave - Consumer Activity Token",
},
{
name: "short",
args: "0x44616920537461626c65636f696e2076312e3000000000000000000000000000",
want: "Dai Stablecoin v1.0",
},
{
name: "short2",
args: "0x44616920537461626c65636f696e2076312e3020444444444444444444444444",
want: "Dai Stablecoin v1.0 DDDDDDDDDDDD",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -9,6 +9,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/golang/protobuf/proto"
"github.com/juju/errors"
"golang.org/x/crypto/sha3"
)

// EthereumTypeAddressDescriptorLen - in case of EthereumType, the AddressDescriptor has fixed length
@@ -176,9 +177,34 @@ func (p *EthereumParser) GetAddrDescFromAddress(address string) (bchain.AddressD
return hex.DecodeString(address)
}

// EIP55Address returns an EIP55-compliant hex string representation of the address
func EIP55Address(addrDesc bchain.AddressDescriptor) string {
raw := hexutil.Encode(addrDesc)
if len(raw) != 42 {
return raw
}
sha := sha3.NewLegacyKeccak256()
result := []byte(raw)
sha.Write(result[2:])
hash := sha.Sum(nil)

for i := 2; i < len(result); i++ {
hashByte := hash[(i-2)>>1]
if i%2 == 0 {
hashByte = hashByte >> 4
} else {
hashByte &= 0xf
}
if result[i] > '9' && hashByte > 7 {
result[i] -= 32
}
}
return string(result)
}

// GetAddressesFromAddrDesc returns addresses for given address descriptor with flag if the addresses are searchable
func (p *EthereumParser) GetAddressesFromAddrDesc(addrDesc bchain.AddressDescriptor) ([]string, bool, error) {
return []string{hexutil.Encode(addrDesc)}, true, nil
return []string{EIP55Address(addrDesc)}, true, nil
}

// GetScriptFromAddrDesc returns output script for given address descriptor
@@ -308,15 +334,15 @@ func (p *EthereumParser) UnpackTx(buf []byte) (*bchain.Tx, uint32, error) {
rt := rpcTransaction{
AccountNonce: hexutil.EncodeUint64(pt.Tx.AccountNonce),
BlockNumber: hexutil.EncodeUint64(uint64(pt.BlockNumber)),
From: hexutil.Encode(pt.Tx.From),
From: EIP55Address(pt.Tx.From),
GasLimit: hexutil.EncodeUint64(pt.Tx.GasLimit),
Hash: hexutil.Encode(pt.Tx.Hash),
Payload: hexutil.Encode(pt.Tx.Payload),
GasPrice: hexEncodeBig(pt.Tx.GasPrice),
// R: hexEncodeBig(pt.R),
// S: hexEncodeBig(pt.S),
// V: hexEncodeBig(pt.V),
To: hexutil.Encode(pt.Tx.To),
To: EIP55Address(pt.Tx.To),
TransactionIndex: hexutil.EncodeUint64(uint64(pt.Tx.TransactionIndex)),
Value: hexEncodeBig(pt.Tx.Value),
}
@@ -329,7 +355,7 @@ func (p *EthereumParser) UnpackTx(buf []byte) (*bchain.Tx, uint32, error) {
topics[j] = hexutil.Encode(t)
}
logs[i] = &rpcLog{
Address: hexutil.Encode(l.Address),
Address: EIP55Address(l.Address),
Data: hexutil.Encode(l.Data),
Topics: topics,
}
@@ -77,14 +77,14 @@ func init() {
Txid: "0xcd647151552b5132b2aef7c9be00dc6f73afc5901dde157aab131335baaa853b",
Vin: []bchain.Vin{
{
Addresses: []string{"0x3e3a3d69dc66ba10737f531ed088954a9ec89d97"},
Addresses: []string{"0x3E3a3D69dc66bA10737F531ed088954a9EC89d97"},
},
},
Vout: []bchain.Vout{
{
ValueSat: *big.NewInt(1999622000000000000),
ScriptPubKey: bchain.ScriptPubKey{
Addresses: []string{"0x555ee11fbddc0e49a9bab358a8941ad95ffdb48f"},
Addresses: []string{"0x555Ee11FBDDc0E49A9bAB358A8941AD95fFDB48f"},
},
},
},
@@ -93,12 +93,12 @@ func init() {
AccountNonce: "0xb26c",
GasPrice: "0x430e23400",
GasLimit: "0x5208",
To: "0x555ee11fbddc0e49a9bab358a8941ad95ffdb48f",
To: "0x555Ee11FBDDc0E49A9bAB358A8941AD95fFDB48f",
Value: "0x1bc0159d530e6000",
Payload: "0x",
Hash: "0xcd647151552b5132b2aef7c9be00dc6f73afc5901dde157aab131335baaa853b",
BlockNumber: "0x41eee8",
From: "0x3e3a3d69dc66ba10737f531ed088954a9ec89d97",
From: "0x3E3a3D69dc66bA10737F531ed088954a9EC89d97",
TransactionIndex: "0xa",
},
Receipt: &rpcReceipt{
@@ -115,14 +115,14 @@ func init() {
Txid: "0xa9cd088aba2131000da6f38a33c20169baee476218deea6b78720700b895b101",
Vin: []bchain.Vin{
{
Addresses: []string{"0x20cd153de35d469ba46127a0c8f18626b59a256a"},
Addresses: []string{"0x20cD153de35D469BA46127A0C8F18626b59a256A"},
},
},
Vout: []bchain.Vout{
{
ValueSat: *big.NewInt(0),
ScriptPubKey: bchain.ScriptPubKey{
Addresses: []string{"0x4af4114f73d1c1c903ac9e0361b379d1291808a2"},
Addresses: []string{"0x4af4114F73d1c1C903aC9E0361b379D1291808A2"},
},
},
},
@@ -131,19 +131,19 @@ func init() {
AccountNonce: "0xd0",
GasPrice: "0x9502f9000",
GasLimit: "0x130d5",
To: "0x4af4114f73d1c1c903ac9e0361b379d1291808a2",
To: "0x4af4114F73d1c1C903aC9E0361b379D1291808A2",
Value: "0x0",
Payload: "0xa9059cbb000000000000000000000000555ee11fbddc0e49a9bab358a8941ad95ffdb48f00000000000000000000000000000000000000000000021e19e0c9bab2400000",
Hash: "0xa9cd088aba2131000da6f38a33c20169baee476218deea6b78720700b895b101",
BlockNumber: "0x41eee8",
From: "0x20cd153de35d469ba46127a0c8f18626b59a256a",
From: "0x20cD153de35D469BA46127A0C8F18626b59a256A",
TransactionIndex: "0x0"},
Receipt: &rpcReceipt{
GasUsed: "0xcb39",
Status: "0x1",
Logs: []*rpcLog{
{
Address: "0x4af4114f73d1c1c903ac9e0361b379d1291808a2",
Address: "0x4af4114F73d1c1C903aC9E0361b379D1291808A2",
Data: "0x00000000000000000000000000000000000000000000021e19e0c9bab2400000",
Topics: []string{
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
@@ -93,4 +93,4 @@ func (p *PolisParser) PackTx(tx *bchain.Tx, height uint32, blockTime int64) ([]b
// UnpackTx unpacks transaction from protobuf byte array
func (p *PolisParser) UnpackTx(buf []byte) (*bchain.Tx, uint32, error) {
return p.baseparser.UnpackTx(buf)
}
}
@@ -1,10 +1,9 @@
package polis

import (
"encoding/json"
"blockbook/bchain"
"blockbook/bchain/coins/btc"
"encoding/json"

"github.com/golang/glog"
"github.com/juju/errors"
)
@@ -14,6 +13,8 @@ type PolisRPC struct {
*btc.BitcoinRPC
}

const firstBlockWithSpecialTransactions = 454000

// NewPolisRPC returns new PolisRPC instance.
func NewPolisRPC(config json.RawMessage, pushHandler func(bchain.NotificationType)) (bchain.BlockChain, error) {
b, err := btc.NewBitcoinRPC(config, pushHandler)
@@ -26,7 +27,6 @@ func NewPolisRPC(config json.RawMessage, pushHandler func(bchain.NotificationTyp
}
s.RPCMarshaler = btc.JSONMarshalerV1{}
s.ChainConfig.SupportsEstimateSmartFee = false

return s, nil
}

@@ -58,7 +58,7 @@ func (b *PolisRPC) Initialize() error {
}

// GetBlock returns block with given hash
func (b *DashRPC) GetBlock(hash string, height uint32) (*bchain.Block, error) {
func (b *PolisRPC) GetBlock(hash string, height uint32) (*bchain.Block, error) {
if hash == "" && height < firstBlockWithSpecialTransactions {
return b.BitcoinRPC.GetBlock(hash, height)
}
@@ -107,6 +107,6 @@ func (b *DashRPC) GetBlock(hash string, height uint32) (*bchain.Block, error) {

// GetTransactionForMempool returns a transaction by the transaction ID.
// It could be optimized for mempool, i.e. without block time and confirmations
func (b *DashRPC) GetTransactionForMempool(txid string) (*bchain.Tx, error) {
func (b *PolisRPC) GetTransactionForMempool(txid string) (*bchain.Tx, error) {
return b.GetTransaction(txid)
}
@@ -76,12 +76,13 @@ type Vout struct {
// Tx is blockchain transaction
// unnecessary fields are commented out to avoid overhead
type Tx struct {
Hex string `json:"hex"`
Txid string `json:"txid"`
Version int32 `json:"version"`
LockTime uint32 `json:"locktime"`
Vin []Vin `json:"vin"`
Vout []Vout `json:"vout"`
Hex string `json:"hex"`
Txid string `json:"txid"`
Version int32 `json:"version"`
LockTime uint32 `json:"locktime"`
Vin []Vin `json:"vin"`
Vout []Vout `json:"vout"`
BlockHeight uint32 `json:"blockHeight,omitempty"`
// BlockHash string `json:"blockhash,omitempty"`
Confirmations uint32 `json:"confirmations,omitempty"`
Time int64 `json:"time,omitempty"`
@@ -4,6 +4,7 @@ server=1
{{if .Backend.Mainnet}}mainnet=1{{else}}testnet=1{{end}}
nolisten=1
txindex=1
disablewallet=1

zmqpubhashtx={{template "IPC.MessageQueueBindingTemplate" .}}
zmqpubhashblock={{template "IPC.MessageQueueBindingTemplate" .}}
@@ -22,10 +22,10 @@
"package_name": "backend-bcash",
"package_revision": "satoshilabs-1",
"system_user": "bcash",
"version": "0.20.1",
"binary_url": "https://download.bitcoinabc.org/0.20.1/linux/bitcoin-abc-0.20.1-x86_64-linux-gnu.tar.gz",
"version": "0.20.2",
"binary_url": "https://download.bitcoinabc.org/0.20.2/linux/bitcoin-abc-0.20.2-x86_64-linux-gnu.tar.gz",
"verification_type": "sha256",
"verification_source": "ad768329ac6347ecad5f71cd42bf26d31159d2dacd028766049d310c0bfa3c04",
"verification_source": "e11d241a8c726abd5c06a091726f0c8a4f92b3506388292b38ce41d7ba95b7c7",
"extract_command": "tar -C backend --strip 1 -xf",
"exclude_files": [
"bin/bitcoin-qt"
@@ -49,7 +49,7 @@
"additional_params": "",
"block_chain": {
"parse": true,
"subversion": "/Bitcoin ABC:0.20.1/",
"subversion": "/Bitcoin ABC:0.20.2/",
"address_format": "cashaddr",
"mempool_workers": 8,
"mempool_sub_workers": 2,
@@ -22,10 +22,10 @@
"package_name": "backend-bcash-testnet",
"package_revision": "satoshilabs-1",
"system_user": "bcash",
"version": "0.20.1",
"binary_url": "https://download.bitcoinabc.org/0.20.1/linux/bitcoin-abc-0.20.1-x86_64-linux-gnu.tar.gz",
"version": "0.20.2",
"binary_url": "https://download.bitcoinabc.org/0.20.2/linux/bitcoin-abc-0.20.2-x86_64-linux-gnu.tar.gz",
"verification_type": "sha256",
"verification_source": "ad768329ac6347ecad5f71cd42bf26d31159d2dacd028766049d310c0bfa3c04",
"verification_source": "e11d241a8c726abd5c06a091726f0c8a4f92b3506388292b38ce41d7ba95b7c7",
"extract_command": "tar -C backend --strip 1 -xf",
"exclude_files": [
"bin/bitcoin-qt"
@@ -49,7 +49,7 @@
"additional_params": "",
"block_chain": {
"parse": true,
"subversion": "/Bitcoin ABC:0.20.1/",
"subversion": "/Bitcoin ABC:0.20.2/",
"address_format": "cashaddr",
"mempool_workers": 8,
"mempool_sub_workers": 2,

0 comments on commit fdfb07b

Please sign in to comment.
You can’t perform that action at this time.