From 1d945230273924858190f6f46f446402583a5e64 Mon Sep 17 00:00:00 2001 From: Ivan Kuznetsov Date: Tue, 8 Jan 2019 16:09:41 +0700 Subject: [PATCH] Add support for 'chain/get_currency_stats' API endpoint --- api.go | 10 +++++++ responses.go | 84 ++++++++++++++++++++++++++++------------------------ 2 files changed, 55 insertions(+), 39 deletions(-) diff --git a/api.go b/api.go index 739c3fc2..23e486a2 100644 --- a/api.go +++ b/api.go @@ -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 { diff --git a/responses.go b/responses.go index 0fee8e04..c782f3dc 100644 --- a/responses.go +++ b/responses.go @@ -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 { @@ -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"` } @@ -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"` @@ -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 { @@ -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"` +}