utils

package
v0.0.0-...-019d704 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CoinbaseWitnessDataLen is the required length of the only element within
	// the coinbase's witness data if the coinbase transaction contains a
	// witness commitment.
	CoinbaseWitnessDataLen = 32

	// CoinbaseWitnessPkScriptLength is the length of the public key script
	// containing an OP_RETURN, the WitnessMagicBytes, and the witness
	// commitment itself. In order to be a valid candidate for the output
	// containing the witness commitment
	CoinbaseWitnessPkScriptLength = 38
)
View Source
const (
	AlertNotification = 0
	InfoNotification  = 1
)
View Source
const BTCBlockConfirmations = 6
View Source
const (
	DEFAULT_RATE_INCREASING_STEP = 1.23
)

Variables

View Source
var (
	// WitnessMagicBytes is the prefix marker within the public key script
	// of a coinbase output to indicate that this output holds the witness
	// commitment for a block.
	WitnessMagicBytes = []byte{
		txscript.OP_RETURN,
		txscript.OP_DATA_36,
		0xaa,
		0x21,
		0xa9,
		0xed,
	}
)

Functions

func BuildBTCClient

func BuildBTCClient() (*rpcclient.Client, error)

func BuildMerkleTreeStore

func BuildMerkleTreeStore(transactions []*btcutil.Tx, witness bool) []*chainhash.Hash

BuildMerkleTreeStore creates a merkle tree from a slice of transactions, stores it using a linear array, and returns a slice of the backing array. A linear array was chosen as opposed to an actual tree structure since it uses about half as much memory. The following describes a merkle tree and how it is stored in a linear array.

A merkle tree is a tree in which every non-leaf node is the hash of its children nodes. A diagram depicting how this works for bitcoin transactions where h(x) is a double sha256 follows:

         root = h1234 = h(h12 + h34)
        /                           \
  h12 = h(h1 + h2)            h34 = h(h3 + h4)
   /            \              /            \
h1 = h(tx1)  h2 = h(tx2)    h3 = h(tx3)  h4 = h(tx4)

The above stored as a linear array is as follows:

[h1 h2 h3 h4 h12 h34 root]

As the above shows, the merkle root is always the last element in the array.

The number of inputs is not always a power of two which results in a balanced tree structure as above. In that case, parent nodes with no children are also zero and parent nodes with only a single left node are calculated by concatenating the left node with itself before hashing. Since this function uses nodes that are pointers to the hashes, empty nodes will be nil.

The additional bool parameter indicates if we are generating the merkle tree using witness transaction id's rather than regular transaction id's. This also presents an additional case wherein the wtxid of the coinbase transaction is the zeroHash.

func BuildProof

func BuildProof(btcClient *rpcclient.Client, txID string, blkHeight uint64) (string, error)

func ConvertExternalBTCAmountToIncAmount

func ConvertExternalBTCAmountToIncAmount(externalBTCAmount int64) int64

ConvertExternalBTCAmountToIncAmount converts amount in bTC chain (decimal 8) to amount in inc chain (decimal 9)

func ConvertIncPBTCAmountToExternalBTCAmount

func ConvertIncPBTCAmountToExternalBTCAmount(incPBTCAmount int64) int64

ConvertIncPBTCAmountToExternalBTCAmount converts amount in inc chain (decimal 9) to amount in bTC chain (decimal 8)

func GetNewFee

func GetNewFee(vsize int, oldFeePerUnshieldRequest uint, numberOfUnshieldRequest uint, currentRelayingFee uint) uint

Get new fee per request (nano pToken)

func HashMerkleBranches

func HashMerkleBranches(left *chainhash.Hash, right *chainhash.Hash) *chainhash.Hash

HashMerkleBranches takes two hashes, treated as the left and right tree nodes, and returns the hash of their concatenation. This is a helper function used to aid in the generation of a merkle tree.

func HexToBytes

func HexToBytes(s string) ([]byte, error)

func IsEnoughFee

func IsEnoughFee(vsize int, feePerRequest uint, numberOfRequest uint, currentRelayingFee uint) bool

func SendSlackNotification

func SendSlackNotification(msg string, notiType int) error

SendSlackNotification will post to an 'Incoming Webook' url setup in Slack Apps. It accepts some text and the slack channel is saved within Slack.

Types

type BTCProof

type BTCProof struct {
	MerkleProofs []*MerkleProof
	BTCTx        *wire.MsgTx
	BlockHash    *chainhash.Hash
}

func ParseBTCProofFromB64EncodeStr

func ParseBTCProofFromB64EncodeStr(b64EncodedStr string) (*BTCProof, error)

type HttpClient

type HttpClient struct {
	*http.Client
	// contains filtered or unexported fields
}

func NewHttpClient

func NewHttpClient(url string, protocol string, host string, port string) *HttpClient

NewHttpClient to get http client instance

func (HttpClient) GetURL

func (client HttpClient) GetURL() string

func (*HttpClient) RPCCall

func (client *HttpClient) RPCCall(
	method string,
	params interface{},
	rpcResponse interface{},
) (err error)

type MerkleProof

type MerkleProof struct {
	ProofHash *chainhash.Hash
	IsLeft    bool
}

func BuildMerkleProof

func BuildMerkleProof(txHashes []*chainhash.Hash, targetedTxHash *chainhash.Hash) []*MerkleProof

type SlackRequestBody

type SlackRequestBody struct {
	Text string `json:"text"`
}

Jump to

Keyboard shortcuts

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