metahash

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2022 License: MIT Imports: 21 Imported by: 0

README

MetaHash API GO library

An unofficial Golang library for #MetaHash blockchain. This repository was folked from the reposity created by xboston and I contributed to the original repository. However, due to major changes I made, I decided to create a new repository to avoid introducing breaking changes to the original repository and affect systems that are already depending on the original repository.

metahash-go

Requirements
  • GO go 1.12+
Installation
go get -u github.com/jwmdev/metahash-go
Information
Methods
  • fetch-balance
  • fetch-balances
  • fetch-history
  • get-tx
  • get-last-txs
  • get-blocks
  • get-block-by-number
  • get-block-by-hash
  • get-dump-block-by-number
  • get-dump-block-by-hash
  • get-count-blocks
  • get-last-node-stat-result
  • get-last-node-stat-trust
  • get-all-last-nodes-count
  • get-nodes-raiting
  • get-address-delegations
  • get-forging-sum-all
  • get-forging-sum
  • get-common-balance
  • status
  • mhc_send
  • getinfo
Extra Methods
Usage

You can find usage examples in the examples folder.

License

This package is released under the MIT license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCommonBalance

func GetCommonBalance() (int64, error)

func GetTotalBlocks

func GetTotalBlocks() (int64, error)

func NewClient

func NewClient(baseUrl string) jsonrpc.RPCClient

Types

type AbstractMethod

type AbstractMethod struct {
	Jsonrpc string      `json:"jsonrpc"`
	Method  string      `json:"method"`
	Params  interface{} `json:"params,omitempty"`
}

type Address

type Address string

Address data type

type AddressDelegations

type AddressDelegations struct {
	Address string `json:"address"`
	States  []struct {
		To    string `json:"to"`
		Value int64  `json:"value"`
		Tx    string `json:"tx"`
	} `json:"states"`
}

func GetAddressDelegations

func GetAddressDelegations(address string, startTx, countTx int64) (*AddressDelegations, error)

type AddressValue added in v1.1.1

type AddressValue struct {
	A string `json:"a"`
	V int64  `json:"v"`
}

type Balance

type Balance struct {
	Address           string `json:"address"`
	Received          int64  `json:"received"`
	Spent             int64  `json:"spent"`
	CountReceived     int64  `json:"count_received"`
	CountSpent        int64  `json:"count_spent"`
	CountTxs          int64  `json:"count_txs"`
	BlockNumber       int64  `json:"block_number"`
	CurrentBlock      int64  `json:"currentBlock"`
	Hash              string `json:"hash"`
	CountDelegatedOps int64  `json:"countDelegatedOps"`
	Delegate          int64  `json:"delegate"`
	Undelegate        int64  `json:"undelegate"`
	Delegated         int64  `json:"delegated"`
	Undelegated       int64  `json:"undelegated"`
	Reserved          int64  `json:"reserved"`
	CountForgedOps    int64  `json:"countForgedOps"`
	Forged            int64  `json:"forged"`
}

func FetchBalance

func FetchBalance(address string) (*Balance, error)

FetchBalance gets the balance information of a given address

func FetchBalances

func FetchBalances(addresses ...string) ([]*Balance, error)

FetchBalances gets the balance information of list of addresses

func (*Balance) CurrentBalance added in v1.0.1

func (b *Balance) CurrentBalance() int64

func (*Balance) DelegatedAmount added in v1.0.1

func (b *Balance) DelegatedAmount() int64

func (*Balance) DelegatedFunds added in v1.0.1

func (b *Balance) DelegatedFunds() int64

DelegatedFunds function determs how much is delegated to the address

func (*Balance) FullBalance added in v1.0.1

func (b *Balance) FullBalance() int64

func (*Balance) Funded added in v1.0.1

func (b *Balance) Funded() int64

Funded function determines how much is the address delegated

func (*Balance) IsNode added in v1.0.1

func (b *Balance) IsNode() bool

func (*Balance) SeedCapital added in v1.0.1

func (b *Balance) SeedCapital() int64

type BalanceArgs

type BalanceArgs struct {
	Address string `json:"address"`
}

type BalancesArgs

type BalancesArgs struct {
	Addresses []string `json:"addresses"`
}

type Block

type Block struct {
	Type       string `json:"type"`
	Hash       string `json:"hash"`
	PrevHash   string `json:"prev_hash"`
	TxHash     string `json:"tx_hash"`
	Number     int64  `json:"number"`
	TimeStamp  int64  `json:"timestamp"`
	CountTxs   int64  `json:"count_txs"`
	Sign       string `json:"sign"`
	Size       int64  `json:"size"`
	FileName   string `json:"fileName"`
	Signatures []struct {
		From        string `json:"from"`
		To          string `json:"to"`
		Value       int64  `json:"value"`
		Transaction string `json:"transaction"`
		Data        string `json:"data"`
		TimeStamp   int64  `json:"timestamp"`
		Type        string `json:"type"`
		BlockNumber int64  `json:"blockNumber"`
		Signature   string `json:"signature"`
		Publickey   string `json:"publickey"`
		Fee         int64  `json:"fee"`
		RealFee     int64  `json:"realFee"`
		Nonce       int64  `json:"nonce"`
		IntStatus   int64  `json:"intStatus"`
		Status      string `json:"status"`
	} `json:"signatures,omitempty"`
	Txs []*TransactionInfo `json:"txs"`
}

func GetBlockByHash

func GetBlockByHash(blockHash string, startIndex, numTx, blockType int) (*Block, error)

func GetBlockByNumber

func GetBlockByNumber(blockNumber int64, blockType BlockType) (*Block, error)

func GetBlockByNumberFilter

func GetBlockByNumberFilter(blockNumber, startTx, numTx int64, blockType BlockType) (*Block, error)

func GetBlocks

func GetBlocks(startBlock, numBlocks int64) ([]*Block, error)

type BlockByHashArgs

type BlockByHashArgs struct {
	Hash     string `json:"hash"`
	BeginTx  int64  `json:"beginTx,omitempty"`
	CountTxs int64  `json:"countTxs,omitempty"`
	Type     int8   `json:"type,omitempty"` // 0-4
}

type BlockByNumberArgs

type BlockByNumberArgs struct {
	Number   int64 `json:"number"`
	BeginTx  int64 `json:"beginTx,omitempty"`
	CountTxs int64 `json:"countTxs,omitempty"`
	Type     int8  `json:"type,omitempty"` // 0-4

}

type BlockType added in v1.1.0

type BlockType int
const (
	NameOnly BlockType = iota
	HashesOnly
	FullDump
)

type BlockType1 added in v1.1.0

type BlockType1 struct {
	Type       string `json:"type,omitempty"`
	Hash       string `json:"hash,omitempty"`
	PrevHash   string `json:"prev_hash,omitempty"`
	TxHash     string `json:"tx_hash,omitempty"`
	Number     int    `json:"number,omitempty"`
	Timestamp  int    `json:"timestamp,omitempty"`
	CountTxs   int    `json:"count_txs,omitempty"`
	Sign       string `json:"sign,omitempty"`
	Size       int    `json:"size,omitempty"`
	FileName   string `json:"fileName,omitempty"`
	Signatures []struct {
		From        string `json:"from,omitempty"`
		To          string `json:"to,omitempty"`
		Value       int    `json:"value,omitempty"`
		Transaction string `json:"transaction,omitempty"`
		Data        string `json:"data,omitempty"`
		Timestamp   int    `json:"timestamp,omitempty"`
		Type        string `json:"type,omitempty"`
		BlockNumber int    `json:"blockNumber,omitempty"`
		Signature   string `json:"signature,omitempty"`
		Publickey   string `json:"publickey,omitempty"`
		Fee         int    `json:"fee,omitempty"`
		RealFee     int    `json:"realFee,omitempty"`
		Nonce       int    `json:"nonce,omitempty"`
		IntStatus   int    `json:"intStatus,omitempty"`
		Status      string `json:"status,omitempty"`
	} `json:"signatures,omitempty"`
	Txs []string `json:"txs,omitempty"`
}

type BlocksArgs

type BlocksArgs struct {
	CountBlocks int64 `json:"countBlocks,omitempty"`
	BeginBlock  int64 `json:"beginBlock,omitempty"`
}

type CommonBalance

type CommonBalance struct {
	Balance int64 `json:"balance"`
}

type CountBlocks

type CountBlocks struct {
	CountBlocks int64 `json:"count_blocks"`
	BeginBlock  int64 `json:"beginBlock"`
}

type CountBlocksArgs

type CountBlocksArgs struct {
}

type DumpBlock

type DumpBlock struct {
	Dump string `json:"dump"`
}

func GetDumpBlockByHash

func GetDumpBlockByHash(blockHash string, isHex bool) (*DumpBlock, error)

func GetDumpBlockByNumber

func GetDumpBlockByNumber(blockNumber int64, isHex bool) (*DumpBlock, error)

type DumpBlockByHashArgs

type DumpBlockByHashArgs struct {
	Hash  string `json:"hash"`
	IsHex bool   `json:"isHex,omitempty"`
}

type DumpBlockByNumberArgs

type DumpBlockByNumberArgs struct {
	Number int64 `json:"number"`
	IsHex  bool  `json:"isHex,omitempty"`
}

type ForginSumArgs

type ForginSumArgs struct {
	BlockIndent int `json:"block_indent"`
}

type ForgingSum

type ForgingSum struct {
	Blocknumber int `json:"blockNumber"`
	Sums        []struct {
		Type  int   `json:"type"`
		Value int64 `json:"value"`
	} `json:"sums"`
}

func GetForgingSum

func GetForgingSum(blockIndent int) (*ForgingSum, error)

func GetForgingSumAll

func GetForgingSumAll() (*ForgingSum, error)

GetForgingSumAll returns sum all types of forging 100; // forging transaction 101; // wallet reward forging transaction 102; // node reward forging transaction 103; // coin reward forging transaction 104; // random reward forging transaction

type HistoryArgs

type HistoryArgs struct {
	Address  string        `json:"address"`
	BeginTx  int64         `json:"beginTx,omitempty"`
	CountTxs int64         `json:"countTxs,omitempty"`
	Filters  HistoryFilter `json:"filters,omitempty"`
}

type HistoryFilter

type HistoryFilter struct {
	IsInput    bool `json:"isInput,omitempty"`    // isInput - Display only isInput transactions
	IsOutput   bool `json:"isOutput,omitempty"`   //isOutput - Display only isOutput transactions
	IsSuccess  bool `json:"isSuccess,omitempty"`  //isSuccess - Display only success transactions
	IsForging  bool `json:"isForging,omitempty"`  //isForging - Display only forging transactions
	IsTest     bool `json:"isTest,omitempty"`     //isTest - Display only test transactions
	IsDelegate bool `json:"isDelegate,omitempty"` //isDelegate - Display only delegation transactions
}

type Key

type Key interface {
	Private() PrivateKey
	Public() PublicKey
	Verify(data []byte, sign string) (bool, error)
	Address() Address
	SetAddress(address string)
	Sign(data []byte) (string, error)
}

Key interface

func CreateKey

func CreateKey(private string) (Key, error)

CreateKey creates metahash keys

func NewKey

func NewKey() (Key, error)

NewKey generates metahash key

type LastNode added in v1.1.1

type LastNode struct {
	Node  string `json:"node"`
	IP    string `json:"ip"`
	Type  string `json:"type"`
	Count int    `json:"count"`
}

type LastNodeCount

type LastNodeCount struct {
	Nodes        []*LastNode `json:"nodes"`
	Day          int         `json:"day"`
	Lastblockday int         `json:"lastBlockDay"`
}

func GetLastNodeCount

func GetLastNodeCount(counts int) (*LastNodeCount, error)

type LastTxsArgs

type LastTxsArgs struct {
}

type MetaKey

type MetaKey struct {
	Key Key //private key in ex format
}

func InitWallet

func InitWallet(walletAddress, privateKey string) (*MetaKey, error)

Iniate a new wallet by supplying the wallet address and private key

func (*MetaKey) SignTransaction

func (mk *MetaKey) SignTransaction(data []byte) (string, error)

SignTransaction generates signature

func (*MetaKey) Transfer

func (mk *MetaKey) Transfer(toAddress string, sendAmount float64) (string, error)

type MetaTx

type MetaTx struct {
	To    string `json:"to"`
	Value int64  `json:"value"`
	Fee   int64  `json:"fee"`
	Data  string `json:"data"`
	Nonce int64  `json:"nonce"`
}

type MetaTxArg

type MetaTxArg struct {
	To     string `json:"to"`
	Value  string `json:"value"`
	Fee    string `json:"fee"`
	Data   string `json:"data"`
	Nonce  string `json:"nonce"`
	Pubkey string `json:"pubkey"`
	Sign   string `json:"sign"`
}

TransactionArgs argument

type MetaTxResp

type MetaTxResp struct {
	Result string
	Params string
	Error  string
}

TransactionResponse response

type Node

type Node struct {
	Address  string `json:"address"`
	Name     string `json:"name"`
	NodeType string `json:"node_type"`

	IP           string  `json:"ip"`
	Latitude     float64 `json:"latitude"`
	Longitude    float64 `json:"longitude"`
	CountryShort string  `json:"country_short" `
	CountryLong  string  `json:"country_long"`
	Region       string  `json:"region"`
	City         string  `json:"city"`

	Geo    string `json:"geo"`
	Status bool   `json:"status"`
	ROI    string `json:"roi" `
	QPS    string `json:"qps" `
	RPS    string `json:"rps"`
	Trust  string `json:"trust"`

	IsOnline bool `json:"is_online" `

	LastUpdated time.Time `json:"last_updated" `
	LastChecked time.Time `json:"last_checked" `
}

Node data struct

type NodeArgs

type NodeArgs struct {
	Address    string `json:"address"`
	BeginTx    int64  `json:"beginTx,omitempty"`
	CountTxs   int64  `json:"countTxs,omitempty"`
	CountTests int    `json:"count_tests,omitempty"`
}

type NodeData

type NodeData struct {
	Address             string   `json:"address"`
	Host                string   `json:"host"`
	Name                string   `json:"name"`
	Type                []string `json:"type"`
	Bench               string   `json:"bench"`
	BenchCnt            string   `json:"bench_cnt"`
	Trust               string   `json:"trust"`
	OnlineStat          string   `json:"online_stat"`
	Balance             string   `json:"balance"`
	Status              string   `json:"status"`
	StatusParams        string   `json:"status_params"`
	Version             string   `json:"version"`
	Rate                string   `json:"rate"`
	LastRewardAmount    string   `json:"last_reward_amount"`
	LastDelegatedAmount string   `json:"last_delegated_amount"`
	Roi                 string   `json:"roi"`
	Sort                string   `json:"sort"`
	Ts                  int      `json:"ts"`
	MaxBenchCnt         string   `json:"max_bench_cnt"`
	Fake                bool     `json:"fake"`
	Online              int      `json:"online"`
	LastTestTs          int64    `json:"last_test_ts"`
	BenchSuccess        float32  `json:"bench_success"`
	AvgRps              int64    `json:"avgRps"`
	IsInternal          bool     `json:"is_internal"`
}

type NodeList

type NodeList struct {
	Data []NodeData
}

NodeList gives the list of all nodes obtained from the network

type NodeParams added in v1.1.1

type NodeParams struct {
	Type              string `json:"type"`
	Ver               string `json:"ver"`
	Address           string `json:"address"`
	Host              string `json:"host"`
	Blockheightcheck  string `json:"blockHeightCheck"`
	Requestsperminute string `json:"requestsPerMinute"`
	Latency           string `json:"latency"`
	Geo               string `json:"geo"`
	Success           string `json:"success"`
}

type NodeRaiting

type NodeRaiting struct {
	Address      string `json:"address"`
	Raiting      int    `json:"raiting"`
	Day          int    `json:"day"`
	Lastblockday int    `json:"lastBlockDay"`
}

type NodeRegistration

type NodeRegistration struct {
	Jsonrpc string `json:"jsonrpc"`
	Method  string `json:"method"`
	Params  struct {
		Host string `json:"host"`
		Name string `json:"name"`
		Type string `json:"type,omitempty"`
	} `json:"params"`
}

внутренние структуры-методы

type NodeStats

type NodeStats struct {
	Address            string `json:"address"`
	Type               string `json:"type"`
	AvgRps             string `json:"avgRps"`
	IsLatency          bool   `json:"isLatency"`
	IP                 string `json:"ip"`
	Geo                string `json:"geo"`
	State              string `json:"state"`
	Timestamp          int    `json:"timestamp"`
	Success            bool   `json:"success"`
	LastBlockTimestamp int    `json:"lastBlockTimestamp"`
}

func GetNodeStats

func GetNodeStats(address string) (*NodeStats, error)

func (*NodeStats) GetTest

func (ns *NodeStats) GetTest() (*NodeStatsState, error)

type NodeStatsState

type NodeStatsState struct {
	ID      string      `json:"id"`
	Jsonrpc string      `json:"jsonrpc"`
	Method  string      `json:"method"`
	Params  *NodeParams `json:"params"`
}

type NodeTest

type NodeTest struct {
	TimeStamp int64          `json:"timestamp"`
	Method    string         `json:"method"`
	Params    *NodeTestParam `json:"params"`
}

type NodeTestParam added in v1.1.1

type NodeTestParam struct {
	Mhaddr   string `json:"mhaddr"`
	IP       string `json:"ip"`
	QPS      int64  `json:"qps"`
	Rps      int64  `json:"rps"`
	Closed   string `json:"closed"`
	Timeouts string `json:"timeouts"`
	Ver      string `json:"ver"`
	Success  string `json:"success"`
}

type NodeTrust

type NodeTrust struct {
	Address            string `json:"address"`
	Trust              int64  `json:"trust"`
	Data               string `json:"data"`
	Timestamp          int64  `json:"timestamp"`
	Lastblocktimestamp int64  `json:"lastBlockTimestamp"`
}

func GetLastNodeStatTrust

func GetLastNodeStatTrust(address string) (*NodeTrust, error)

func (*NodeTrust) GetTrustData

func (nt *NodeTrust) GetTrustData() (*NodeTrustData, error)

GetTrustData returns trust and list of delete to and delegate from

type NodeTrustData

type NodeTrustData struct {
	State         int             `json:"state"`
	Trust         int             `json:"trust"`
	DelegateTo    []*AddressValue `json:"delegate_to"`
	DelegatedFrom []*AddressValue `json:"delegated_from"`
}

func (*NodeTrustData) Delegated added in v1.0.3

func (ntd *NodeTrustData) Delegated() (delegatedTo int64, delegatedFrom int64)

Delegated function returns node delegated to and node delegated from

type PrivateKey

type PrivateKey string

PrivateKey data type

type PublicKey

type PublicKey string

PublicKey data type

type Status

type Status struct {
	ID      int    `json:"id"`
	Result  string `json:"result"`
	Version string `json:"version"`
	GitHash string `json:"git_hash"`
}

type TotalSupply

type TotalSupply struct {
	CirculatingSupply    string `json:"circulating_supply"`     //Number of coins in circulation
	CirculatingSupplyCmc string `json:"circulating_supply_cmc"` //Number of coins in circulation (by CoinMarketCap)
	TotalSupply          string `json:"total_supply"`           //Number of all coins emitted
	TotalSupplyDecimals  string `json:"total_supply_decimals"`  //Number of all coins emitted in micro units
	MaxSupply            string `json:"max_supply"`             //Maximum possible number of coins
	Decimals             int    `json:"decimals"`               //Number of decimal places
	Name                 string `json:"name"`                   //Name of the currency
}

func MetahashSupply

func MetahashSupply() (*TotalSupply, error)

type Transaction

type Transaction struct {
	Transaction TransactionInfo `json:"transaction"`
	CountBlocks int64           `json:"countBlocks"`
	KnownBlocks int64           `json:"knownBlocks"`
}

func GetTransaction

func GetTransaction(txHash string) (*Transaction, error)

GetTransaction returns the transaction details given the transaction hash

type TransactionArgs

type TransactionArgs struct {
	Hash string `json:"hash"`
}

type TransactionInfo

type TransactionInfo struct {
	From         string `json:"from" db:"fromA"`
	To           string `json:"to" db:"toA"`
	Value        int64  `json:"value"`
	Transaction  string `json:"transaction"`
	Data         string `json:"data,omitempty"`
	TimeStamp    int64  `json:"timestamp" db:"timestamp,int64"`
	Type         string `json:"type" db:"typeTx"`
	BlockNumber  int64  `json:"blockNumber" db:"blockNumber"`
	Signature    string `json:"signature,omitempty"`
	PublicKey    string `json:"publickey"`
	Fee          int64  `json:"fee"`
	RealFee      int64  `json:"realFee" db:"realFee"`
	Nonce        int64  `json:"nonce"`
	IntStatus    int64  `json:"intStatus" db:"intStatus"`
	Status       string `json:"status"`
	IsDelegate   bool   `json:"isDelegate,omitempty" db:"isDelegate"`
	DelegateInfo struct {
		IsDelegate   bool   `json:"isDelegate"`
		Delegate     int64  `json:"delegate,omitempty"`
		DelegateHash string `json:"delegateHash,omitempty"`
	} `json:"delegate_info,omitempty" db:"-"`
	Delegate     int64  `json:"delegate,omitempty"`
	DelegateHash string `json:"delegateHash,omitempty" db:"delegateHash"`
}

func FetchHistory

func FetchHistory(address string) ([]*TransactionInfo, error)

FetchHistory returns all transactions history of a given address

func FetchHistoryFilter

func FetchHistoryFilter(address string, countTx int64, filter *HistoryFilter) ([]*TransactionInfo, error)

This function is not working because of the metahash api error FetchHistoryFilter returns list of transaction history based on the provide filter

func FetchHistoryRange

func FetchHistoryRange(address string, startIndex, numTrx int64) ([]*TransactionInfo, error)

FetchHistoryRange returns list of transaction history from a given index

func GetLastTransactions

func GetLastTransactions() ([]*TransactionInfo, error)

GetLastTransactions returns the list of last transactions made

type Varint

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

func NewVarint

func NewVarint() *Varint

NewVarint creates a new variant

func (*Varint) Append

func (vt *Varint) Append(number *big.Int) error

Append adds data to the variant

func (*Varint) AppendBytes

func (vt *Varint) AppendBytes(bytes []byte)

AppendBytes appends bytes to the variant

func (*Varint) AppendString

func (vt *Varint) AppendString(str string) error

AppendString appends string to the variant

func (*Varint) GetBytes

func (vt *Varint) GetBytes() []byte

GetBytes returns byte data from variant

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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