2018-07-27 00:36:45 +02:00
// Copyright (c) 2017-2018 The Bitcoin Core developers
2017-09-29 06:21:28 +02:00
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
# ifndef BITCOIN_RPC_UTIL_H
# define BITCOIN_RPC_UTIL_H
2017-12-04 18:49:20 +01:00
# include <pubkey.h>
# include <script/standard.h>
# include <univalue.h>
2017-09-29 06:21:28 +02:00
# include <string>
# include <vector>
class CKeyStore ;
class CPubKey ;
class CScript ;
2017-05-30 21:55:17 +02:00
struct InitInterfaces ;
//! Pointers to interfaces that need to be accessible from RPC methods. Due to
//! limitations of the RPC framework, there's currently no direct way to pass in
//! state to RPC method implementations.
extern InitInterfaces * g_rpc_interfaces ;
2017-09-29 06:21:28 +02:00
CPubKey HexToPubKey ( const std : : string & hex_in ) ;
CPubKey AddrToPubKey ( CKeyStore * const keystore , const std : : string & addr_in ) ;
CScript CreateMultisigRedeemscript ( const int required , const std : : vector < CPubKey > & pubkeys ) ;
2017-12-04 18:49:20 +01:00
UniValue DescribeAddress ( const CTxDestination & dest ) ;
2018-10-23 21:22:28 +02:00
struct RPCArg {
enum class Type {
OBJ ,
ARR ,
STR ,
NUM ,
BOOL ,
OBJ_USER_KEYS , //!< Special type where the user must set the keys e.g. to define multiple addresses; as opposed to e.g. an options object where the keys are predefined
AMOUNT , //!< Special type representing a floating point amount (can be either NUM or STR)
STR_HEX , //!< Special type that is a STR with only hex chars
} ;
const std : : string m_name ; //!< The name of the arg (can be empty for inner args)
const Type m_type ;
const std : : vector < RPCArg > m_inner ; //!< Only used for arrays or dicts
const bool m_optional ;
2018-10-20 14:19:44 +02:00
const std : : string m_oneline_description ; //!< Should be empty unless it is supposed to override the auto-generated summary line
2018-10-23 21:22:28 +02:00
2018-10-20 14:19:44 +02:00
RPCArg ( const std : : string & name , const Type & type , const bool optional , const std : : string & oneline_description = " " )
: m_name { name } , m_type { type } , m_optional { optional } , m_oneline_description { oneline_description }
2018-10-23 21:22:28 +02:00
{
assert ( type ! = Type : : ARR & & type ! = Type : : OBJ ) ;
}
2018-10-20 14:19:44 +02:00
RPCArg ( const std : : string & name , const Type & type , const std : : vector < RPCArg > & inner , const bool optional , const std : : string & oneline_description = " " )
: m_name { name } , m_type { type } , m_inner { inner } , m_optional { optional } , m_oneline_description { oneline_description }
2018-10-23 21:22:28 +02:00
{
assert ( type = = Type : : ARR | | type = = Type : : OBJ ) ;
}
std : : string ToString ( ) const ;
private :
std : : string ToStringObj ( ) const ;
} ;
class RPCHelpMan
{
public :
2018-10-20 14:19:44 +02:00
RPCHelpMan ( const std : : string & name , const std : : string & description , const std : : vector < RPCArg > & args )
: m_name { name } , m_description { description } , m_args { args }
2018-10-23 21:22:28 +02:00
{
}
std : : string ToString ( ) const ;
private :
const std : : string m_name ;
2018-10-20 14:19:44 +02:00
const std : : string m_description ;
2018-10-23 21:22:28 +02:00
const std : : vector < RPCArg > m_args ;
} ;
2017-09-29 06:21:28 +02:00
# endif // BITCOIN_RPC_UTIL_H