lbry

package
v0.0.7-0...-0581f6b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 8, 2020 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DeploymentTestDummy ...
	DeploymentTestDummy = iota

	// DeploymentCSV ...
	DeploymentCSV

	// DeploymentSegwit ...
	DeploymentSegwit

	// DefinedDeployments ...
	DefinedDeployments
)
View Source
const (
	// Blockchain is lbry.
	Blockchain string = "lbry"

	// MainnetNetwork is the value of the network
	// in MainnetNetworkIdentifier.
	MainnetNetwork string = "Mainnet"

	// TestnetNetwork is the value of the network
	// in TestnetNetworkIdentifier.
	TestnetNetwork string = "Testnet3"

	// Decimals is the decimals value
	// used in Currency.
	Decimals = 8

	// SatoshisInlbry is the number of
	// Satoshis in 1 LBC (10^8).
	SatoshisInlbry = 100000000

	// InputOpType is used to describe
	// INPUT.
	InputOpType = "INPUT"

	// OutputOpType is used to describe
	// OUTPUT.
	OutputOpType = "OUTPUT"

	// CoinbaseOpType is used to describe
	// Coinbase.
	CoinbaseOpType = "COINBASE"

	// SuccessStatus is the status of all
	// lbry operations because anything
	// on-chain is considered successful.
	SuccessStatus = "SUCCESS"

	// SkippedStatus is the status of all
	// operations that are skipped because
	// of BIP-30. You can read more about these
	// types of operations in BIP-30.
	SkippedStatus = "SKIPPED"

	// TransactionHashLength is the length
	// of any transaction hash in lbry.
	TransactionHashLength = 64

	// NullData is returned by lbrycrdd
	// as the ScriptPubKey.Type for OP_RETURN
	// locking scripts.
	NullData = "nulldata"
)
View Source
const (
	MinFeeRate            = float64(0.00001) // nolint:gomnd
	TransactionOverhead   = 12               // 4 version, 2 segwit flag, 1 vin, 1 vout, 4 lock time
	InputSize             = 68               // 4 prev index, 32 prev hash, 4 sequence, 1 script size, ~27 script witness
	OutputOverhead        = 9                // 8 value, 1 script size
	P2PKHScriptPubkeySize = 25               // P2PKH size
)

Fee estimate constants Source: https://lbryops.org/en/tools/calc-size/

Variables

View Source
var (
	// ErrBlockNotFound is returned by when the requested block
	// cannot be found by the node
	ErrBlockNotFound = errors.New("unable to find block")

	// ErrJSONRPCError is returned when receiving an error from a JSON-RPC response
	ErrJSONRPCError = errors.New("JSON-RPC error")
)
View Source
var (
	// MainnetGenesisBlockIdentifier is the genesis block for mainnet.
	MainnetGenesisBlockIdentifier = &types.BlockIdentifier{
		Hash: "9c89283ba0f3227f6c03b70216b9f665f0118d5e0fa729cedf4fb34d6a34f463",
	}

	// MainnetParams are the params for mainnet.
	MainnetParams = &LbryMainnetParams

	// MainnetCurrency is the *types.Currency for mainnet.
	MainnetCurrency = &types.Currency{
		Symbol:   "LBC",
		Decimals: Decimals,
	}

	// TestnetGenesisBlockIdentifier is the genesis block for testnet.
	TestnetGenesisBlockIdentifier = &types.BlockIdentifier{
		Hash: "9c89283ba0f3227f6c03b70216b9f665f0118d5e0fa729cedf4fb34d6a34f463",
	}

	// TestnetParams are the params for testnet.
	TestnetParams = &chaincfg.TestNet3Params

	// TestnetCurrency is the *types.Currency for testnet.
	TestnetCurrency = &types.Currency{
		Symbol:   "tLBC",
		Decimals: Decimals,
	}

	// OperationTypes are all supported operation.Types.
	OperationTypes = []string{
		InputOpType,
		OutputOpType,
		CoinbaseOpType,
	}

	// OperationStatuses are all supported operation.Status.
	OperationStatuses = []*types.OperationStatus{
		{
			Status:     SuccessStatus,
			Successful: true,
		},
		{
			Status:     SkippedStatus,
			Successful: false,
		},
	}
)
View Source
var LbryMainnetParams = chaincfg.Params{
	Name:        "mainnet",
	Net:         0xfae4aaf1,
	DefaultPort: "9246",

	GenesisBlock: &genesisBlock,
	GenesisHash:  &genesisHash,

	Bech32HRPSegwit: "lbc",

	PubKeyHashAddrID:        85,
	ScriptHashAddrID:        122,
	PrivateKeyID:            28,
	WitnessPubKeyHashAddrID: 0x06,
	WitnessScriptHashAddrID: 0x0A,
	BIP0034Height:           1,
	BIP0065Height:           200000,
	BIP0066Height:           200000,

	HDPrivateKeyID: [4]byte{0x04, 0x88, 0xad, 0xe4},
	HDPublicKeyID:  [4]byte{0x04, 0x88, 0xb2, 0x1e},

	HDCoinType: 0x8c,
}

MainNetParams returns the chain configuration for mainnet

View Source
var LbryTestnetParams = chaincfg.Params{
	Name:        "testnet",
	Net:         0xfae4aae1,
	DefaultPort: "19246",

	GenesisBlock: &genesisBlock,
	GenesisHash:  &genesisHash,

	Bech32HRPSegwit: "tlbc",

	PubKeyHashAddrID:        111,
	ScriptHashAddrID:        196,
	PrivateKeyID:            239,
	WitnessPubKeyHashAddrID: 0x06,
	WitnessScriptHashAddrID: 0x0A,
	BIP0034Height:           1,
	BIP0065Height:           200000,
	BIP0066Height:           200000,

	HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94},
	HDPublicKeyID:  [4]byte{0x04, 0x35, 0x87, 0xcf},

	HDCoinType: 0x8c,
}

TestnetParams returns the chain configuration for testnet

Functions

func CoinIdentifier

func CoinIdentifier(hash string, vout int64) string

CoinIdentifier converts a tx hash and vout into the canonical CoinIdentifier.Identifier used in rosetta-lbry.

func LocalhostURL

func LocalhostURL(rpcPort int) string

LocalhostURL returns the URL to use for a client that is running at localhost.

func ParseCoinIdentifier

func ParseCoinIdentifier(coinIdentifier *types.CoinIdentifier) (*chainhash.Hash, uint32, error)

ParseCoinIdentifier returns the corresponding hash and index associated with a *types.CoinIdentifier.

func ParseSingleAddress

func ParseSingleAddress(
	chainParams *chaincfg.Params,
	script []byte,
) (txscript.ScriptClass, btcutil.Address, error)

ParseSingleAddress extracts a single address from a pkscript or throws an error.

func Startlbrycrdd

func Startlbrycrdd(ctx context.Context, configPath string, g *errgroup.Group) error

Startlbrycrdd starts a lbrycrdd daemon in another goroutine and logs the results to the console.

func TransactionHash

func TransactionHash(identifier string) string

TransactionHash extracts the transaction hash from a CoinIdentifier.Identifier.

Types

type Block

type Block struct {
	Hash              string  `json:"hash"`
	Height            int64   `json:"height"`
	PreviousBlockHash string  `json:"previousblockhash"`
	Time              int64   `json:"time"`
	MedianTime        int64   `json:"mediantime"`
	Nonce             int64   `json:"nonce"`
	MerkleRoot        string  `json:"merkleroot"`
	Version           int32   `json:"version"`
	Size              int64   `json:"size"`
	Weight            int64   `json:"weight"`
	Bits              string  `json:"bits"`
	Difficulty        float64 `json:"difficulty"`

	Txs []*Transaction `json:"tx"`
}

Block is a raw lbry block (with verbosity == 2).

func (Block) Metadata

func (b Block) Metadata() (map[string]interface{}, error)

Metadata returns the metadata for a block.

type BlockMetadata

type BlockMetadata struct {
	Nonce      int64   `json:"nonce,omitempty"`
	MerkleRoot string  `json:"merkleroot,omitempty"`
	Version    int32   `json:"version,omitempty"`
	Size       int64   `json:"size,omitempty"`
	Weight     int64   `json:"weight,omitempty"`
	MedianTime int64   `json:"mediantime,omitempty"`
	Bits       string  `json:"bits,omitempty"`
	Difficulty float64 `json:"difficulty,omitempty"`
}

BlockMetadata is a collection of useful metadata in a block.

type BlockchainInfo

type BlockchainInfo struct {
	Chain         string `json:"chain"`
	Blocks        int64  `json:"blocks"`
	BestBlockHash string `json:"bestblockhash"`
}

BlockchainInfo is information about the lbry network. This struct only contains the information necessary for this implementation.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is used to fetch blocks from lbrycrdd and to parse lbry block data into Rosetta types.

We opted not to use existing lbry RPC libraries because they don't allow providing context in each request.

func NewClient

func NewClient(
	baseURL string,
	genesisBlockIdentifier *types.BlockIdentifier,
	currency *types.Currency,
) *Client

NewClient creates a new lbry client.

func (*Client) GetPeers

func (b *Client) GetPeers(ctx context.Context) ([]*types.Peer, error)

GetPeers fetches the list of peer nodes

func (*Client) GetRawBlock

func (b *Client) GetRawBlock(
	ctx context.Context,
	identifier *types.PartialBlockIdentifier,
) (*Block, []string, error)

GetRawBlock fetches a block (block) by *types.PartialBlockIdentifier.

func (*Client) NetworkStatus

func (b *Client) NetworkStatus(ctx context.Context) (*types.NetworkStatusResponse, error)

NetworkStatus returns the *types.NetworkStatusResponse for lbrycrdd.

func (*Client) ParseBlock

func (b *Client) ParseBlock(
	ctx context.Context,
	block *Block,
	coins map[string]*types.AccountCoin,
) (*types.Block, error)

ParseBlock returns a parsed lbry block given a raw lbry block and a map of transactions containing inputs.

func (*Client) PruneBlockchain

func (b *Client) PruneBlockchain(
	ctx context.Context,
	height int64,
) (int64, error)

PruneBlockchain prunes up to the provided height. https://lbrycore.org/en/doc/0.20.0/rpc/blockchain/pruneblockchain

func (*Client) RawMempool

func (b *Client) RawMempool(
	ctx context.Context,
) ([]string, error)

RawMempool returns an array of all transaction hashes currently in the mempool.

func (*Client) SendRawTransaction

func (b *Client) SendRawTransaction(
	ctx context.Context,
	serializedTx string,
) (string, error)

SendRawTransaction submits a serialized transaction to lbrycrdd.

func (*Client) SuggestedFeeRate

func (b *Client) SuggestedFeeRate(
	ctx context.Context,
	confTarget int64,
) (float64, error)

SuggestedFeeRate estimates the approximate fee per vKB needed to get a transaction in a block within conf_target.

type Input

type Input struct {
	TxHash      string     `json:"txid"`
	Vout        int64      `json:"vout"`
	ScriptSig   *ScriptSig `json:"scriptSig"`
	Sequence    int64      `json:"sequence"`
	TxInWitness []string   `json:"txinwitness"`

	// Relevant when the input is the coinbase input
	Coinbase string `json:"coinbase"`
}

Input is a raw input in a lbry transaction.

func (Input) Metadata

func (i Input) Metadata() (map[string]interface{}, error)

Metadata returns the metadata for an input.

type OperationMetadata

type OperationMetadata struct {
	// Coinbase Metadata
	Coinbase string `json:"coinbase,omitempty"`

	// Input Metadata
	ScriptSig   *ScriptSig `json:"scriptsig,omitempty"`
	Sequence    int64      `json:"sequence,omitempty"`
	TxInWitness []string   `json:"txinwitness,omitempty"`

	// Output Metadata
	ScriptPubKey *ScriptPubKey `json:"scriptPubKey,omitempty"`
}

OperationMetadata is a collection of useful metadata from lbry inputs and outputs.

type Output

type Output struct {
	Value        float64       `json:"value"`
	Index        int64         `json:"n"`
	ScriptPubKey *ScriptPubKey `json:"scriptPubKey"`
}

Output is a raw output in a lbry transaction.

func (Output) Metadata

func (o Output) Metadata() (map[string]interface{}, error)

Metadata returns the metadata for an output.

type PeerInfo

type PeerInfo struct {
	Addr           string `json:"addr"`
	Version        int64  `json:"version"`
	SubVer         string `json:"subver"`
	StartingHeight int64  `json:"startingheight"`
	RelayTxes      bool   `json:"relaytxes"`
	LastSend       int64  `json:"lastsend"`
	LastRecv       int64  `json:"lastrecv"`
	BanScore       int64  `json:"banscore"`
	SyncedBlocks   int64  `json:"synced_blocks"`
	SyncedHeaders  int64  `json:"synced_headers"`
}

PeerInfo is a collection of relevant info about a particular peer.

type ScriptPubKey

type ScriptPubKey struct {
	ASM          string   `json:"asm"`
	Hex          string   `json:"hex"`
	RequiredSigs int64    `json:"reqSigs,omitempty"`
	Type         string   `json:"type"`
	Addresses    []string `json:"addresses,omitempty"`
}

ScriptPubKey is a script placed on the output operations of a lbry transaction that must be satisfied to spend the output.

type ScriptSig

type ScriptSig struct {
	ASM string `json:"asm"`
	Hex string `json:"hex"`
}

ScriptSig is a script on the input operations of a lbry transaction that satisfies the ScriptPubKey on an output being spent.

type Transaction

type Transaction struct {
	Hex      string `json:"hex"`
	Hash     string `json:"txid"`
	Size     int64  `json:"size"`
	Vsize    int64  `json:"vsize"`
	Version  int32  `json:"version"`
	Locktime int64  `json:"locktime"`
	Weight   int64  `json:"weight"`

	Inputs  []*Input  `json:"vin"`
	Outputs []*Output `json:"vout"`
}

Transaction is a raw lbry transaction.

func (Transaction) Metadata

func (t Transaction) Metadata() (map[string]interface{}, error)

Metadata returns the metadata for a transaction.

type TransactionMetadata

type TransactionMetadata struct {
	Size     int64 `json:"size,omitempty"`
	Vsize    int64 `json:"vsize,omitempty"`
	Version  int32 `json:"version,omitempty"`
	Locktime int64 `json:"locktime,omitempty"`
	Weight   int64 `json:"weight,omitempty"`
}

TransactionMetadata is a collection of useful metadata in a transaction.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL