Skip to content

Commit

Permalink
Add support for 'chain/get_currency_stats' API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeiwan committed Jan 8, 2019
1 parent 5e4b22c commit 1d94523
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 39 deletions.
10 changes: 10 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,16 @@ func (api *API) GetCurrencyBalance(account AccountName, symbol string, code Acco
return
}

func (api *API) GetCurrencyStats(code AccountName, symbol string) (out *GetCurrencyStatsResp, err error) {
params := M{"code": code, "symbol": symbol}

outWrapper := make(map[string]*GetCurrencyStatsResp)
err = api.call("chain", "get_currency_stats", params, &outWrapper)
out = outWrapper[symbol]

return
}

// See more here: libraries/chain/contracts/abi_serializer.cpp:58...

func (api *API) call(baseAPI string, endpoint string, body interface{}, out interface{}) error {
Expand Down
84 changes: 45 additions & 39 deletions responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ type InfoResp struct {
HeadBlockTime JSONTime `json:"head_block_time"` // "2018-02-02T04:19:32"
HeadBlockProducer AccountName `json:"head_block_producer"` // "inita"

VirtualBlockCPULimit Int64 `json:"virtual_block_cpu_limit"`
VirtualBlockNetLimit Int64 `json:"virtual_block_net_limit"`
BlockCPULimit Int64 `json:"block_cpu_limit"`
BlockNetLimit Int64 `json:"block_net_limit"`
ServerVersionString string `json:"server_version_string"`
VirtualBlockCPULimit Int64 `json:"virtual_block_cpu_limit"`
VirtualBlockNetLimit Int64 `json:"virtual_block_net_limit"`
BlockCPULimit Int64 `json:"block_cpu_limit"`
BlockNetLimit Int64 `json:"block_net_limit"`
ServerVersionString string `json:"server_version_string"`
}

type BlockResp struct {
Expand Down Expand Up @@ -68,8 +68,8 @@ type DBSizeResp struct {
UsedBytes Int64 `json:"used_bytes"`
Size Int64 `json:"size"`
Indices []struct {
Index string `json:"index"`
RowCount Int64 `json:"row_count"`
Index string `json:"index"`
RowCount Int64 `json:"row_count"`
} `json:"indices"`
}

Expand Down Expand Up @@ -166,8 +166,8 @@ type AccountResp struct {
CoreLiquidBalance Asset `json:"core_liquid_balance"`
RAMQuota int64 `json:"ram_quota"`
RAMUsage int64 `json:"ram_usage"`
NetWeight Int64 `json:"net_weight"`
CPUWeight Int64 `json:"cpu_weight"`
NetWeight Int64 `json:"net_weight"`
CPUWeight Int64 `json:"cpu_weight"`
NetLimit AccountResourceLimit `json:"net_limit"`
CPULimit AccountResourceLimit `json:"cpu_limit"`
Permissions []Permission `json:"permissions"`
Expand Down Expand Up @@ -326,36 +326,36 @@ type NetConnectResp string
type NetDisconnectResp string

type Global struct {
MaxBlockNetUsage int `json:"max_block_net_usage"`
TargetBlockNetUsagePct int `json:"target_block_net_usage_pct"`
MaxTransactionNetUsage int `json:"max_transaction_net_usage"`
BasePerTransactionNetUsage int `json:"base_per_transaction_net_usage"`
NetUsageLeeway int `json:"net_usage_leeway"`
ContextFreeDiscountNetUsageNum int `json:"context_free_discount_net_usage_num"`
ContextFreeDiscountNetUsageDen int `json:"context_free_discount_net_usage_den"`
MaxBlockCPUUsage int `json:"max_block_cpu_usage"`
TargetBlockCPUUsagePct int `json:"target_block_cpu_usage_pct"`
MaxTransactionCPUUsage int `json:"max_transaction_cpu_usage"`
MinTransactionCPUUsage int `json:"min_transaction_cpu_usage"`
MaxTransactionLifetime int `json:"max_transaction_lifetime"`
DeferredTrxExpirationWindow int `json:"deferred_trx_expiration_window"`
MaxTransactionDelay int `json:"max_transaction_delay"`
MaxInlineActionSize int `json:"max_inline_action_size"`
MaxInlineActionDepth int `json:"max_inline_action_depth"`
MaxAuthorityDepth int `json:"max_authority_depth"`
MaxRAMSize string `json:"max_ram_size"`
TotalRAMBytesReserved Int64 `json:"total_ram_bytes_reserved"`
TotalRAMStake Int64 `json:"total_ram_stake"`
LastProducerScheduleUpdate string `json:"last_producer_schedule_update"`
LastPervoteBucketFill int64 `json:"last_pervote_bucket_fill,string"`
PervoteBucket int `json:"pervote_bucket"`
PerblockBucket int `json:"perblock_bucket"`
TotalUnpaidBlocks int `json:"total_unpaid_blocks"`
TotalActivatedStake float64 `json:"total_activated_stake,string"`
ThreshActivatedStakeTime int64 `json:"thresh_activated_stake_time,string"`
LastProducerScheduleSize int `json:"last_producer_schedule_size"`
TotalProducerVoteWeight float64 `json:"total_producer_vote_weight,string"`
LastNameClose string `json:"last_name_close"`
MaxBlockNetUsage int `json:"max_block_net_usage"`
TargetBlockNetUsagePct int `json:"target_block_net_usage_pct"`
MaxTransactionNetUsage int `json:"max_transaction_net_usage"`
BasePerTransactionNetUsage int `json:"base_per_transaction_net_usage"`
NetUsageLeeway int `json:"net_usage_leeway"`
ContextFreeDiscountNetUsageNum int `json:"context_free_discount_net_usage_num"`
ContextFreeDiscountNetUsageDen int `json:"context_free_discount_net_usage_den"`
MaxBlockCPUUsage int `json:"max_block_cpu_usage"`
TargetBlockCPUUsagePct int `json:"target_block_cpu_usage_pct"`
MaxTransactionCPUUsage int `json:"max_transaction_cpu_usage"`
MinTransactionCPUUsage int `json:"min_transaction_cpu_usage"`
MaxTransactionLifetime int `json:"max_transaction_lifetime"`
DeferredTrxExpirationWindow int `json:"deferred_trx_expiration_window"`
MaxTransactionDelay int `json:"max_transaction_delay"`
MaxInlineActionSize int `json:"max_inline_action_size"`
MaxInlineActionDepth int `json:"max_inline_action_depth"`
MaxAuthorityDepth int `json:"max_authority_depth"`
MaxRAMSize string `json:"max_ram_size"`
TotalRAMBytesReserved Int64 `json:"total_ram_bytes_reserved"`
TotalRAMStake Int64 `json:"total_ram_stake"`
LastProducerScheduleUpdate string `json:"last_producer_schedule_update"`
LastPervoteBucketFill int64 `json:"last_pervote_bucket_fill,string"`
PervoteBucket int `json:"pervote_bucket"`
PerblockBucket int `json:"perblock_bucket"`
TotalUnpaidBlocks int `json:"total_unpaid_blocks"`
TotalActivatedStake float64 `json:"total_activated_stake,string"`
ThreshActivatedStakeTime int64 `json:"thresh_activated_stake_time,string"`
LastProducerScheduleSize int `json:"last_producer_schedule_size"`
TotalProducerVoteWeight float64 `json:"total_producer_vote_weight,string"`
LastNameClose string `json:"last_name_close"`
}

type Producer struct {
Expand Down Expand Up @@ -387,3 +387,9 @@ type ActionsResp struct {
Actions []ActionResp `json:"actions"`
LastIrreversibleBlock uint32 `json:"last_irreversible_block"`
}

type GetCurrencyStatsResp struct {
Supply Asset `json:"supply"`
MaxSupply Asset `json:"max_supply"`
Issuer AccountName `json:"issuer"`
}

0 comments on commit 1d94523

Please sign in to comment.