util

package
v0.0.0-...-db4ab52 Latest Latest
Warning

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

Go to latest
Published: May 15, 2019 License: ISC Imports: 42 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCannotVerifyPayment is emitted when a transaction cannot be verified
	// because it cannot reach either of the block explorer servers.
	ErrCannotVerifyPayment = errors.New("cannot verify payment at this time")
)
View Source
var (
	ErrInvalidWSCommand = errors.New("invalid webssocket command")
)

Functions

func Base64File

func Base64File(filename string) (string, error)

Base64File returns the base64 content of a file.

func CleanAndExpandPath

func CleanAndExpandPath(path string) string

CleanAndExpandPath expands environment variables and leading ~ in the passed path, cleans the result, and returns it.

func ConvertBodyToByteArray

func ConvertBodyToByteArray(r io.Reader, print bool) []byte

ConvertBodyToByteArray converts a response body into a byte array and optionally prints it to stdout.

func ConvertDigest

func ConvertDigest(d string) ([sha256.Size]byte, bool)

ConvertDigest converts a string into a digest.

func ConvertSignature

func ConvertSignature(s string) ([identity.SignatureSize]byte, error)

ConvertSignature converts a hex encoded signature to a proper sized byte slice.

func ConvertStringToken

func ConvertStringToken(token string) ([]byte, error)

ConvertStringToken verifies and converts a string token to a proper sized []byte.

func CreateProposalNameRegex

func CreateProposalNameRegex() string

CreateProposalNameRegex returns a regex string for matching the proposal name

func DerivePaywallAddress

func DerivePaywallAddress(params *chaincfg.Params, xpub string, index uint32) (string, error)

DerivePaywallAddress derives a paywall address using the provided xpub and index.

func Digest

func Digest(b []byte) []byte

Digest returns the SHA256 of a byte slice.

func DigestFile

func DigestFile(filename string) (string, error)

DigestFile returns the SHA256 of a file.

func DigestFileBytes

func DigestFileBytes(filename string) ([]byte, error)

DigestFileBytes returns the SHA256 of a file.

func FQDN

func FQDN() string

FQDN returns the fully qualified domain name of the machine it is running on.

func FetchTxWithBlockExplorers

func FetchTxWithBlockExplorers(address string, amount uint64, txnotbefore int64, minConfirmations uint64) (string, uint64, error)

FetchTxWithBlockExplorers uses public block explorers to look for a transaction for the given address that equals or exceeds the given amount, occurs after the txnotbefore time and has the minimum number of confirmations.

func FileExists

func FileExists(name string) bool

FilesExists reports whether the named file or directory exists.

func FnoStringToAmount

func FnoStringToAmount(fnostr string) (uint64, error)

FnoStringToAmount converts a FNO amount as a string into a uint64 representing atoms. Supported input variations: "1", ".1", "0.1"

func GenCertPair

func GenCertPair(curve elliptic.Curve, org, certFile, keyFile string) error

GenCertPair generates a key/cert pair to the paths provided.

func GetErrorFromJSON

func GetErrorFromJSON(r io.Reader) (interface{}, error)

GetErrorFromJSON returns the error that is embedded in a JSON reply.

func GetProposalName

func GetProposalName(payload string) (string, error)

ProposalName returns a proposal name

func IdentityFromString

func IdentityFromString(id string) (*identity.PublicIdentity, error)

IdentityFromString converts a string public key into a public identity structure.

func IsDigest

func IsDigest(digest string) bool

IsDigest determines if a string is a valid SHA256 digest.

func IsValidProposalName

func IsValidProposalName(str string) bool

IsValidProposalName reports whether str is a valid proposal name

func LoadFile

func LoadFile(filename string) (mimeType string, digest string, payload string, err error)

LoadFile loads a file of disk and returns the MIME type, the sha256 digest and the payload encoded as base64. If any of the intermediary operations fail the function will return an error instead.

func MimeFile

func MimeFile(filename string) (string, error)

MimeFile returns the MIME type of a file.

func NewClient

func NewClient(skipVerify bool, certFilename string) (*http.Client, error)

NewClient returns a new http.Client instance

func NormalizeAddress

func NormalizeAddress(addr, defaultPort string) string

NormalizeAddress returns addr with the passed default port appended if there is not already a port specified.

func ParseGetParams

func ParseGetParams(r *http.Request, dst interface{}) error

ParseGetParams parses the query params from the GET request into a struct. This method requires the struct type to be defined with `schema` tags.

func PayWithTestnetFaucet

func PayWithTestnetFaucet(faucetURL string, address string, amount uint64, overridetoken string) (string, error)

PayWithTestnetFaucet makes a request to the testnet faucet.

func Random

func Random(n int) ([]byte, error)

Random returns a variable number of bytes of random data.

func RandomUint64

func RandomUint64() (uint64, error)

RandomInt returns a random unsigned integer.

func RemoteIdentity

func RemoteIdentity(skipTLSVerify bool, host, cert string) (*identity.PublicIdentity, error)

RemoteIdentity fetches the identity from politeiad.

func RespondWithCopy

func RespondWithCopy(w http.ResponseWriter, code int, contentType string, body []byte) error

func RespondWithError

func RespondWithError(w http.ResponseWriter, code int, message string)

func RespondWithJSON

func RespondWithJSON(w http.ResponseWriter, code int, payload interface{})

func SubsciptionReqAuth

func SubsciptionReqAuth(cmd string) bool

func Timestamp

func Timestamp(host string, digests []*[sha256.Size]byte) error

Timestamp sends a Timestamp request to the provided host. The caller is responsible for assembling the host string based on what net to use.

func ValidSubscription

func ValidSubscription(cmd string) bool

func Verify

func Verify(host string, digests []string) (*v1.VerifyReply, error)

Verify sends a fnotime Verify command to the provided host. It checks and validates the entire reply. A single failure is considered terminal and an error is returned. If the reply is valid it is returned to the caller for further processing. This means that the caller can be assured that all checks have been done and the data is readily usable.

func VerifyChallenge

func VerifyChallenge(id *identity.PublicIdentity, challenge []byte, signature string) error

VerifyChallenge checks that the signature returned from politeiad is the challenge signed with the given identity.

func WSJSON

func WSJSON(cmd, id string, payload interface{}) ([][]byte, error)

WSJSON returns the JSON representation of a wire command. This function must always match WSWrite.

func WSRead

func WSRead(c *websocket.Conn) (string, string, interface{}, error)

func WSWrite

func WSWrite(c *websocket.Conn, cmd, id string, payload interface{}) error

func Zero

func Zero(in []byte)

Zero out a byte slice.

Types

type BEBackupTransaction

type BEBackupTransaction struct {
	Address       string      `json:"address"`       // Transaction address
	TxId          string      `json:"txid"`          // Transaction id
	Amount        json.Number `json:"amount"`        // Transaction amount (in FNO)
	Confirmations uint64      `json:"confirmations"` // Number of confirmations
	Timestamp     int64       `json:"ts"`            // Transaction timestamp
}

BEBackupTransaction is an object representing a transaction; it's part of the data returned from the URL for the backup block explorer when fetching the transactions for an address.

type BEPrimaryTransaction

type BEPrimaryTransaction struct {
	TxId          string                     `json:"txid"`          // Transaction id
	Vout          []BEPrimaryTransactionVout `json:"vout"`          // Transaction outputs
	Confirmations uint64                     `json:"confirmations"` // Number of confirmations
	Timestamp     int64                      `json:"time"`          // Transaction timestamp
}

BEPrimaryTransaction is an object representing a transaction; it's part of the data returned from the URL for the primary block explorer when fetching the transactions for an address.

type BEPrimaryTransactionScriptPubkey

type BEPrimaryTransactionScriptPubkey struct {
	Addresses []string `json:"addresses"` // Array of transaction input addresses
}

BEPrimaryTransactionScriptPubkey holds the script info for a transaction.

type BEPrimaryTransactionVout

type BEPrimaryTransactionVout struct {
	Amount       json.Number                      `json:"value"`        // Transaction amount (in FNO)
	ScriptPubkey BEPrimaryTransactionScriptPubkey `json:"scriptPubkey"` // Transaction script info
}

BEPrimaryTransactionVout holds the transaction amount information.

type FaucetResponse

type FaucetResponse struct {
	Txid  string
	Error string
}

FaucetResponse represents the expected JSON response from the testnet faucet.

type PaywallGatewayNewOrderResponse

type PaywallGatewayNewOrderResponse struct {
	Error         string
	OrderID       string
	PaywallAmount uint64
}

PaywallGatewayNewOrderResponse respresents the expected JSON response to a PaywallGatewayNewOrder command.

type TxDetails

type TxDetails struct {
	Address       string // Transaction address
	TxID          string // Transacion ID
	Amount        uint64 // Transaction amount (in atoms)
	Timestamp     int64  // Transaction timestamp
	Confirmations uint64 // Number of confirmations
}

TxDetails is an object representing a transaction that is used to standardize the different responses from fnodata and insight.

func FetchTxsForAddress

func FetchTxsForAddress(address string) ([]TxDetails, error)

FetchTxsForAddress fetches the transactions that have been sent to the provided wallet address from the fnodata block explorer. If the fnodata request fails the insight block explorer is tried.

func FetchTxsForAddressNotBefore

func FetchTxsForAddressNotBefore(address string, notBefore int64) ([]TxDetails, error)

FetchTxsForAddressNotBefore fetches all transactions for a wallet address that occurred after the passed in notBefore timestamp.

Directories

Path Synopsis
Package version provides a single location to house the version information for fnod and other utilities provided in the same repository.
Package version provides a single location to house the version information for fnod and other utilities provided in the same repository.

Jump to

Keyboard shortcuts

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