@@ -118,7 +118,8 @@
|
||||
},
|
||||
{
|
||||
"ac_name": "EQL",
|
||||
"ac_supply": "500000000"
|
||||
"ac_supply": "500000000",
|
||||
"ac_ccactivate": "205000"
|
||||
},
|
||||
{
|
||||
"ac_name": "ZILLA",
|
||||
|
||||
@@ -33,7 +33,7 @@ echo $pubkey
|
||||
./komodod -pubkey=$pubkey -ac_name=PRLPAY -ac_supply=500000000 -addnode=13.250.226.125 &
|
||||
./komodod -pubkey=$pubkey -ac_name=DSEC -ac_supply=7000000 -addnode=185.148.147.30 &
|
||||
./komodod -pubkey=$pubkey -ac_name=GLXT -ac_supply=10000000000 -addnode=13.230.224.15 &
|
||||
./komodod -pubkey=$pubkey -ac_name=EQL -ac_supply=500000000 -addnode=46.101.124.153 &
|
||||
./komodod -pubkey=$pubkey -ac_name=EQL -ac_supply=500000000 -ac_ccactivate=205000 -addnode=46.101.124.153 &
|
||||
./komodod -pubkey=$pubkey -ac_name=ZILLA -ac_supply=11000000 -addnode=54.39.23.248 &
|
||||
./komodod -pubkey=$pubkey -ac_name=RFOX -ac_supply=1000000000 -ac_reward=100000000 -addnode=78.47.196.146 &
|
||||
~/VerusCoin/src/komodod -pubkey=$pubkey -ac_name=VRSC -ac_algo=verushash -ac_cc=1 -ac_veruspos=50 -ac_supply=0 -ac_eras=3 -ac_reward=0,38400000000,2400000000 -ac_halving=1,43200,1051920 -ac_decay=100000000,0,0 -ac_end=10080,226080,0 -ac_timelockgte=19200000000 -ac_timeunlockfrom=129600 -ac_timeunlockto=1180800 -addnode=185.25.48.236 -addnode=185.64.105.111 &
|
||||
|
||||
@@ -1,719 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Copyright © 2014-2018 The SuperNET Developers. *
|
||||
* *
|
||||
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
|
||||
* the top-level directory of this distribution for the individual copyright *
|
||||
* holder information and the developer policies on copyright and licensing. *
|
||||
* *
|
||||
* Unless otherwise agreed in a custom licensing agreement, no part of the *
|
||||
* SuperNET software, including this file may be copied, modified, propagated *
|
||||
* or distributed except according to the terms contained in the LICENSE file *
|
||||
* *
|
||||
* Removal or modification of this copyright notice is prohibited. *
|
||||
* *
|
||||
******************************************************************************/
|
||||
|
||||
How to write utxo based CryptoConditions contracts for KMD chains
|
||||
by jl777
|
||||
|
||||
This is not the only smart contracts methodology that is possible to build on top of OP_CHECKCRYPTOCONDITION, just the first one. All the credit for getting OP_CHECKCRYPTOCONDITION working in the Komodo codebase goes to @libscott. I am just hooking into the code that he made and tried to make it just a little easier to make new contracts.
|
||||
|
||||
There is probably some fancy marketing name to use, but for now, I will just call it "CC contract" for short, knowing that it is not 100% technically accurate as the CryptoConditions aspect is not really the main attribute. However, the KMD contracts were built to make the CryptoConditions codebase that was integrated into it to be more accessible.
|
||||
|
||||
Since CC contracts run native C/C++ code, it is turing complete and that means that any contract that is possible to do on any other platform will be possible to create via CC contract.
|
||||
|
||||
utxo based contracts are a bit harder to start writing than for balance based contracts. However, they are much more secure as they leverage the existing bitcoin utxo system. That makes it much harder to have bugs that issue a zillion new coins from a bug, since all the CC contract operations needs to also obey the existing bitcoin utxo protocol.
|
||||
|
||||
This document will be heavily example based so it will utilize many of the existing reference CC contracts. After understanding this document, you should be in a good position to start creating either a new CC contract to be integrated into komodod or to make rpc based dapps directly.
|
||||
|
||||
Chapter 0 - Bitcoin Protocol Basics
|
||||
There are many aspects of the bitcoin protocol that isnt needed to understand the CC contracts dependence on it. Such details will not be discussed. The primary aspect is the utxo, unspent transaction output. Just a fancy name for txid/vout, so when you sendtoaddress some coins, it creates a txid and the first output is vout.0, combine it and txid/0 is a specific utxo.
|
||||
|
||||
Of course, to understand even this level of detail requires that you understand what a txid is, but there are plenty of reference materials on that. It is basically the 64 char long set of letters and numbers that you get when you send funds.
|
||||
|
||||
Implicit with the utxo is that it prevents double spends. Once you spend a utxo, you cant spend it again. This is quite an important characteristic and while advanced readers will point out chain reorgs can allow a double spend, we will not confuse the issue with such details. The important thing is that given a blockchain at a specific height's blockhash, you can know if a txid/vout has been spent or not.
|
||||
|
||||
There are also the transactions that are in memory waiting to be mined, the mempool. And it is possible for the utxo to be spent by a tx in the mempool. However since it isnt confirmed yet, it is still unspent at the current height, even if we are pretty sure it will be spent in the next block.
|
||||
|
||||
A useful example is to think about a queue of people lined up to get into an event. They need to have a valid ticket and also to get into the queue. After some time passes, they get their ticket stamped and allowed into the event.
|
||||
|
||||
In the utxo case, the ticket is the spending transaction and the event is the confirmed blockchain. The queue is the mempool.
|
||||
|
||||
|
||||
Chapter 1 - OP_CHECKCRYPTOCONDITION
|
||||
In the prior chapter the utxo was explained. However, the specific mechanism used to send a payment was not explained. Contrary to what most people might think, on the blockchain there are not entries that say "pay X amount to address". Instead what exists is a bitcoin script that must be satisfied in order for the funds to be able to be spent.
|
||||
|
||||
Originally, there was the pay to pubkey script:
|
||||
<pubkey> <checksig>
|
||||
|
||||
About as simple of a payment script that you can get. Basically the pubkey's signature is checked and if it is valid, you get to spend it. One problem satoshi realized was that with Quantum Computers such payment scripts are vulnerable! So, he made a way to have a cold address, ie. an address whose pubkey isnt known. At least it isnt known until it is spent, so it is only Quantum resistant prior to the first spend. This line of reasoning is why we have one time use addresses and a new change address for each transaction. Maybe in some ways, this is too forward thinking as it makes things a lot more confusing to use and easier to lose track of all the required private keys.
|
||||
|
||||
However, it is here to stay and its script is:
|
||||
<hash the pubkey> <pubkey> <verify hash matches> <checksig>
|
||||
|
||||
With this, the blockchain has what maps to "pay to address", just that the address is actually a base58 encoded (prefix + pubkeyhash). Hey, if it wasnt complicated, it would be easy!
|
||||
|
||||
In order to spend a p2pkh (pay to pubkey hash) utxo, you need to divulge the pubkey in addition to having a valid signature. After the first spend from an address, its security is degraded to p2pk (pay to pubkey) as its pubkey is now known. The net result is that each reused address takes 25 extra bytes on the blockchain, and that is why for addresses that are expected to be reused, I just use the p2pk script.
|
||||
|
||||
Originally, bitcoin allowed any type of script opcodes to be used directly. The problem was some of them caused problems and satoshi decided to disable them and only allow standard forms of payments. Thus the p2pk and p2pkh became 99%+ of bitcoin transactions. However, going from having a fully scriptable language that can create countless payment scripts (and bugs!), to having just 2... well it was a "short term" limitation. It did last for some years but eventually a compromise p2sh script was allowed to be standard. This is a pay to script hash, so it can have a standard format as the normal p2pkh, but have infinitely more flexibility.
|
||||
|
||||
<hash the script> <script> <verify hash matches>
|
||||
|
||||
Wait, something is wrong! If it was just that, then anybody that found out what the required script (called redeemscript) was, they could just spend it. I forgot to say that the redeemscript is then used to determine if the payment can be spent or not. So you can have a normal p2pk or p2pkh redeemscript inside a p2sh script.
|
||||
|
||||
OK, I know that just got really confusing. Let us have a more clear example:
|
||||
|
||||
redeemscript <- pay to pubkey
|
||||
p2sh becomes the hash of the redeem script + the compares
|
||||
|
||||
So to spend it, you need to divulge the redeemscript, which in turn requires you to divulge the pubkey. Put it all together and the p2sh mechanism verifies you not only had the correct redeemscript by comparing its hash, but that when the redeemscript is run, it is satisfied. In this case, that the pubkey's signature was valid.
|
||||
|
||||
If you are still following, there is some good news! OP_CHECKCRYPTOCONDITION scripts are actually simpler than p2sh scripts in some sense as there isnt this extra level of script inside a scripthash. @libscott implemented the addition of OP_CHECKCRYPTOCONDITION to the set of bitcoin opcodes and what it does is makes sure that a CryptoConditions script is properly signed.
|
||||
|
||||
Which gets us to the CryptoConditions specification, which is a monster of a IETF (Internet standards) draft and has hundred(s) of pages of specification. I am sure you are happy to know that you dont really need to know about it much at all! Just know that you can create all sorts of cryptoconditions and its binary encoding can be used in a bitcoin utxo. If the standard CC contracts dont have the power you need, it is always possible to expand on it. So far, most all the CC contracts only need the power of a 1of1 CC script, which is 1 signature combined with custom constraints. The realtime payment channels CC is the only one of the reference CC contracts so far that didnt fit into this model, it needed a 1of2 CC script.
|
||||
|
||||
The best part is that all these opcode level things are not needed at all. I just wanted to explain it for those that need to know all the details of everything.
|
||||
|
||||
Chapter 2 - CC contract basics
|
||||
Each CC contract has an eval code, this is just an arbitrary number that is associated with a specific CC contract. The details about a specific CC contract are all determined by the validation logic, that is ultimately what implements a CC contract.
|
||||
|
||||
However, unlike the normal bitcoin payments, where it is validated with only information in the transaction, a CC contract has the power to do pretty much anything. It has full access to the blockchain and even the mempool, though using mempool information is inherently more risky and needs to be done carefully or for exclusions, rather than inclusions.
|
||||
|
||||
However, this is the CC contract basics chapter, so let us ignore mempool issues and deal with just the basics. Fundamentally there is no structure for OP_CHECKCRYPTOCONDITION serialized scripts, but if you are like me, you want to avoid having to read and understand a 1000 page IETF standard. What we really want to do is have a logical way to make a new contract and have it be able to be coded and debugged in an efficient way.
|
||||
|
||||
That means to just follow a known working template and only changing the things where the existing templates are not sufficient, ie. the core differentiator of your CC contract.
|
||||
|
||||
In the ~/komodo/src/cc/eval.h file all the eval codes are defined, currently:
|
||||
|
||||
#define FOREACH_EVAL(EVAL) \
|
||||
EVAL(EVAL_IMPORTPAYOUT, 0xe1) \
|
||||
EVAL(EVAL_IMPORTCOIN, 0xe2) \
|
||||
EVAL(EVAL_ASSETS, 0xe3) \
|
||||
EVAL(EVAL_FAUCET, 0xe4) \
|
||||
EVAL(EVAL_REWARDS, 0xe5) \
|
||||
EVAL(EVAL_DICE, 0xe6) \
|
||||
EVAL(EVAL_FSM, 0xe7) \
|
||||
EVAL(EVAL_AUCTION, 0xe8) \
|
||||
EVAL(EVAL_LOTTO, 0xe9) \
|
||||
EVAL(EVAL_HEIR, 0xea) \
|
||||
EVAL(EVAL_CHANNELS, 0xeb) \
|
||||
EVAL(EVAL_ORACLES, 0xec) \
|
||||
EVAL(EVAL_PRICES, 0xed) \
|
||||
EVAL(EVAL_PEGS, 0xee) \
|
||||
EVAL(EVAL_TRIGGERS, 0xef) \
|
||||
EVAL(EVAL_PAYMENTS, 0xf0) \
|
||||
EVAL(EVAL_GATEWAYS, 0xf1)
|
||||
|
||||
Ultimately, we will probably end up with all 256 eval codes used, for now there is plenty of room. I imagined that similar to my coins repo, we can end up with a much larger than 256 number of CC contracts and you select the 256 that you want active for your blockchain. That does mean any specific chain will be limited to "only" having 256 contracts. Since there seems to be so few actually useful contracts so far, this limit seems to be sufficient. I am told that the evalcode can be of any length, but the current CC contracts assumes it is one byte.
|
||||
|
||||
The simplest CC script would be one that requires a signature from a pubkey along with a CC validation. This is the equivalent of the pay to pubkey bitcoin script and is what most of the initial CC contracts use. Only the channels one needed more than this and it will be explained in its chapter.
|
||||
|
||||
We end up with CC scripts of the form (evalcode) + (pubkey) + (other stuff), dont worry about the other stuff, it is automatically handled with some handy internal functions. The important thing to note is that each CC contract of this form needs a single pubkey and eval code and from that we get the CC script. Using the standard bitcoin's "hash and make an address from it" method, this means that the same pubkey will generate a different address for each different CC contract!
|
||||
|
||||
This is an important point, so I will say it in a different way. In bitcoin there used to be uncompressed pubkeys which had both the right and left half combined, into a giant 64 byte pubkey. But since you can derive one from the other, compressed pubkeys became the standard, that is why you have bitcoin pubkeys of 33 bytes instead of 65 bytes. There is a 02, 03 or 04 prefix, to mean odd or even or big pubkey. This means there are two different pubkeys for each privkey, the compressed and uncompressed. And in fact you can have two different bitcoin protocol addresses that are spendable by the same privkey. If you use some paper wallet generators, you might have noticed this.
|
||||
|
||||
CC contracts are like that, where each pubkey gets a different address for each evalcode. It is the same pubkey, just different address due to the actual script having a different evalcode, it ends up with a different hash and thus a different address. Now funds send to a specific CC address is only accessible by that CC contract and must follow the rules of that contract.
|
||||
|
||||
I also added another very useful feature where the convention is for each CC contract to have a special address that is known to all, including its private key. Before you panic about publishing the private key, remember that to spend a CC output, you need to properly sign it AND satisfy all the rules. By everyone having the privkey for the CC contract, everybody can do the "properly sign" part, but they still need to follow the rest of the rules.
|
||||
|
||||
From a user's perspective, there is the global CC address for a CC contract and some contracts also use the user pubkey's CC address. Having a pair of new addresses for each contract can get a bit confusing at first, but eventually we will get easy to use GUI that will make it all easy to use.
|
||||
|
||||
|
||||
Chapter 3 - CC vins and vouts
|
||||
You might want to review the bitcoin basics and other materials to refresh about how bitcoin outputs become inputs. It is a bit complicated, but ultimately it is about one specific amount of coins that are spent, once spent it is combined with the other coins that are also spent in that transaction and then various outputs are created.
|
||||
|
||||
vin0 + vin1 + vin2 -> vout0 + vout1
|
||||
|
||||
That is a 3 input, 2 output transaction. The value from the three inputs are combined and then split into vout0 and vout1, each of the vouts gets a spend script that must be satisfied to be able to be spent. Which means for all three of out vins, all the requirements (as specified in the output that created them) are satisfied.
|
||||
|
||||
Yes, I know this is a bit too complicated without a nice chart, so we will hope that a nice chart is added here:
|
||||
|
||||
[nice chart goes here]
|
||||
|
||||
Out of all the aspects of the CC contracts, the flexibility that different vins and vouts created was the biggest surprise. When I started writing the first of these a month ago, I had no idea the power inherent in the smart utxo contracts. I was just happy to have a way to lock funds and release them upon some specific conditions.
|
||||
|
||||
After the assets/tokens CC contract, I realized that it was just a tip of the iceberg. I knew it was Turing complete, but after all these years of restricted bitcoin script, to have the full power of any arbitrary algorithm, it was eye opening. Years of writing blockchain code and having really bad consequences with every bug naturally makes you gun shy about doing aggressive things at the consensus level. And that is the way it should be, if not very careful, some really bad things can and do happen. The foundation of building on top of the existing (well tested and reliable) utxo system is what makes the CC contracts less likely for the monster bugs. That being said, lack of validation can easily allow an improperly coded CC contract to have its funds drained.
|
||||
|
||||
The CC contract breaks out of the standard limitations of a bitcoin transaction. Already, what I wrote explains the reason, but it was not obvious even to me at first, so likely you might have missed it too. If you are wondering what on earth I am talking about, THAT is what I am talking about!
|
||||
|
||||
To recap, we have now a new standard bitcoin output type called a CC output. Further, there can be up to 256 different types of CC outputs active on any given blockchain. We also know that to spend any output, you need to satisfy its spending script, which in our case is the signature and whatever constraints the CC validation imposes. We also have the convention of a globally shared keypair, which gives us a general CC address that can have funds sent to it, along with a user pubkey specific CC address.
|
||||
|
||||
Let us go back to the 3+2 transaction example:
|
||||
|
||||
vin0 + vin1 + vin2 -> vout0 + vout1
|
||||
|
||||
Given the prior paragraph, try to imagine the possibilities the simple 3+2 transaction can be. Each vin could be a normal vin, from the global contract address, the user's CC address and the vouts can also have this range. Theoretically, there can be 257 * 257 * 257 * 257 * 257 forms of a 3+2 transaction!
|
||||
|
||||
In reality, we really dont want that much degrees of freedom as it will ensure a large degree of bugs! So we need to reduce things to a more manageable level where there are at most 3 types for each, and preferably just 1 type. That will make the job of validating it much simpler and simple is better as long as we dont sacrifice the power. We dont.
|
||||
|
||||
Ultimately the CC contract is all about how it constrains its inputs, but before it can constrain them, they need to be created as outputs. More about this in the CC validation chapter.
|
||||
|
||||
Chapter 4 - CC rpc extensions
|
||||
Currently, CC contracts need to be integrated at the source level. This limits who is able to create and add new CC contracts, which at first is good, but eventually will be a too strict limitation. The runtime bindings chapter will touch on how to break out of the source based limitation, but there is another key interface level, the RPC.
|
||||
|
||||
By convention, each CC contract adds an associated set of rpc calls to the komodo-cli. This not only simplifies the creation of the CC contract transactions, it further will allow dapps to be created just via rpc calls. That will require there being enough foundational CC contracts already in place. As we find new usecases that cannot be implemented via rpc, then a new CC contract is made that can handle that (and more) and the power of the rpc level increases. This is a long term process.
|
||||
|
||||
The typical rpc calls that are added <CC>address, <CClist>, <CCinfo> return the various special CC addresses, the list of CC contract instances and info about each CC contract instance. Along with an rpc that creates a CC instance and of course the calls to invoke a CC instance.
|
||||
|
||||
The role of the rpc calls are to create properly signed rawtransactions that are ready for broadcasting. This then allows using only the rpc calls to not only invoke but to create a specific instance of a CC. The faucet contract is special in that it only has a single instance, so some of these rpc calls are skipped.
|
||||
|
||||
So, there is no MUSTHAVE rpc calls, just a sane convention to follow so it fits into the general pattern.
|
||||
|
||||
One thing that I forgot to describe was how to create a special CC address and even though this is not really an rpc issue, it is kind of separate from the core CC functions, so I will show how to do it here:
|
||||
|
||||
const char *FaucetCCaddr = "R9zHrofhRbub7ER77B7NrVch3A63R39GuC";
|
||||
const char *FaucetNormaladdr = "RKQV4oYs4rvxAWx1J43VnT73rSTVtUeckk";
|
||||
char FaucetCChexstr[67] = { "03682b255c40d0cde8faee381a1a50bbb89980ff24539cb8518e294d3a63cefe12" };
|
||||
uint8_t FaucetCCpriv[32] = { 0xd4, 0x4f, 0xf2, 0x31, 0x71, 0x7d, 0x28, 0x02, 0x4b, 0xc7, 0xdd, 0x71, 0xa0, 0x39, 0xc4, 0xbe, 0x1a, 0xfe, 0xeb, 0xc2, 0x46, 0xda, 0x76, 0xf8, 0x07, 0x53, 0x3d, 0x96, 0xb4, 0xca, 0xa0, 0xe9 };
|
||||
|
||||
Above are the specifics for the faucet CC, but each one has the equivalent in CCcustom.cpp. At the bottom of the file is a big switch statement where these values are copied into an in memory data structure for each CC type. This allows all the CC codebase to access these special addresses in a standard way.
|
||||
|
||||
In order to get the above values, follow these steps:
|
||||
A. use getnewaddress to get a new address and put that in the <CC>Normaladdr = ""; line
|
||||
B. use validateaddress <newaddress from A> to get the pubkey, which is put into the <CC>hexstr[67] = ""; line
|
||||
C. stop the daemon and start with -pubkey=<pubkey from B> and do a <CC>address rpc call. In the console you will get a printout of the hex for the privkey, assuming the if ( 0 ) in Myprivkey() is enabled (CCutils.cpp)
|
||||
D. update the CCaddress and privkey and dont forget to change the -pubkey= parameter
|
||||
|
||||
The first rpc command to add is <CC>address and to do that, add a line to rpcserver.h and update the commands array in rpcserver.cpp
|
||||
|
||||
In the rpcwallet.cpp file you will find the actual rpc functions, find one of the <CC>address ones, copy paste, change the eval code to your eval code and customize the function. Oh, and dont forget to add an entry into eval.h
|
||||
|
||||
Now you have made your own CC contract, but it wont link as you still need to implement the actual functions of it. This will be covered in the following chapters.
|
||||
|
||||
|
||||
Chapter 5 - CC validation
|
||||
CC validation is what its all about, not the "hokey pokey"!
|
||||
|
||||
Each CC must have its own validation function and when the blockchain is validating a transaction, it will call the CC validation code. It is totally up to the CC validation whether to validate it or not.
|
||||
|
||||
Any set of rules that you can think of and implement can be part of the validation. Make sure that there is no ambiguity! Make sure that all transactions that should be rejected are in fact rejected.
|
||||
|
||||
Also, make sure any rpc calls that create a CC transaction dont create anything that doesnt validate.
|
||||
|
||||
Really, that is all that needs to be said about validation that is generic, as it is just a concept and gets a dedicated function to determine if a transaction is valid or not.
|
||||
|
||||
For most of the initial CC contracts, I made a function code for various functions of the CC contract and add that along with the creation txid. That enables the validation of the transactions much easier, as the required data is right there in the opreturn.
|
||||
|
||||
You do need to be careful not to cause a deadlock as the CC validation code is called while already locked in the main loop of the bitcoin protocol. As long as the provided CC contracts are used as models, you should keep out of deadlock troubles.
|
||||
|
||||
|
||||
Chapter 6 - faucet example
|
||||
Finally, we are ready for the first actual example of a CC contract. The faucet. This is a very simple contract and it ran into some interesting bugs in the first incarnation.
|
||||
|
||||
The code in ~/komodo/src/cc/faucet.cpp is the ultimate documentation for it with all the details, so I will just address the conceptual issues here.
|
||||
|
||||
The idea is that people send funds to the faucet by locking it in faucet's global CC address and anybody is allowed to create a faucetget transaction that spends it.
|
||||
|
||||
There are only 7 functions in faucet.cpp, a bit over 200 lines including comments. The first three are for validation, the last four for the rpc calls to use.
|
||||
|
||||
int64_t IsFaucetvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v)
|
||||
|
||||
bool FaucetExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee)
|
||||
|
||||
bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx)
|
||||
|
||||
int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs)
|
||||
|
||||
std::string FaucetGet(uint64_t txfee)
|
||||
|
||||
std::string FaucetFund(uint64_t txfee,int64_t funds)
|
||||
|
||||
UniValue FaucetInfo()
|
||||
|
||||
Functions in rpcwallet implement:
|
||||
|
||||
faucetaddress fully implemented in rpcwallet.cpp
|
||||
faucetfund calls FaucetFund
|
||||
faucetget calls FaucetGet
|
||||
faucetinfo calls FaucetInfo
|
||||
|
||||
Now you might not be a programmer, but I hope you are able to understand the above sequence. user types in a cli call, komodo-cli processes it by calling the rpc function, which in turn calls the function inside faucet.cpp
|
||||
|
||||
No magic, just simple conversion of a user command line call that runs code inside the komodod. Both the faucetfund and faucetget create properly signed rawtransaction that is ready to be broadcast to the network using the standard sendrawtransaction rpc. It doesnt automatically do this to allow the GUI to have a confirmation step with all the details before doing an irrevocable CC contract transaction.
|
||||
|
||||
faucetfund allows anybody to add funds to the faucet
|
||||
faucetget allows anybody to get 0.1 coins from the faucet as long as they dont violate the rules.
|
||||
|
||||
And we come to what it is all about. The rules of the faucet. Initially it was much less strict and that allowed it to be drained slowly, but automatically and it prevented most from being able to use the faucet.
|
||||
|
||||
To make it much harder to leech, it was made so each faucetget returned only 0.1 coins (down from 1.0) so it was worth 90% less. It was also made so that it had to be to a fresh address with less than 3 transactions. Finally each txid was constrained to start and end with 00! This is a cool trick to force usage of precious CPU time (20 to 60 seconds depending on system) to generate a valid txid. Like PoW mining for the txid and I expect other CC contracts to use a similar mechanism if they want to rate limit usage.
|
||||
|
||||
Combined, it became such a pain to get 0.1 coins, the faucet leeching problem was solved. It might not seem like too much trouble to change an address to get another 0.1 coins, but the way things are setup you need to launch the komodod -pubkey=<your pubkey> to change the pubkey that is active for a node. That means to change the pubkey being used, the komodod needs to be restarted and this creates a lot of issues for any automation trying to do this. Combined with the PoW required, only when 0.1 coins becomes worth a significant effort will faucet leeching return. In that case, the PoW requirement can be increased and coin amount decreased, likely with a faucet2 CC contract as I dont expect many such variations to be needed.
|
||||
|
||||
Chapter 7 - rewards example
|
||||
The next CC contract in complexity is the rewards CC contract. This is designed to capture what most people like about masternodes, without anything else, ie. the rewards!
|
||||
|
||||
The idea is to allow people to lock funds for some amount of time and get an extra reward. We also want to support having more than one rewards plan at a time and to allow customization of plan details. One twist that makes it a bit unexpected is that anybody should be able to unlock the funds that were locked, as long as it ends up in the locking address. The reason for this is that SPV servers want to be supported and while locking can be done via normal sendrawtransaction, it requires a native node to do the unlocking. By allowing anybody to be able to unlock, then there can be a special node that unlocks all locked funds when they are ready. This way, from the user's point of view, they lock the funds and after it is matured, it reappears in their wallet.
|
||||
|
||||
The above requirements leads us to using the global CC address for the rewards contract to lock the funds in. That allows anybody to properly sign the unlock, but of course that is not enough, we need to make sure they are following all the unlock requirements. Primarily that the funds go back to the locking address.
|
||||
|
||||
The four aspects of the rewards plan that are customizable are:
|
||||
APR, minseconds, maxseconds, mindeposit
|
||||
|
||||
This allows each plan to set a different APR (up to 25%, anything above is becoming silly), the minimum time funds must be locked, the maximum time they are earning rewards and the minimum that can be deposited.
|
||||
|
||||
So the tx that creates the rewards plan will have these attributes and it is put into the OP_RETURN data. All the other calls will reference the plan creation txid and inherit these parameters from the creation tx. This means it is an important validation to do, to make sure the funding txid is a valid funding txid.
|
||||
|
||||
Since it is possible that the initial funding will be used up, there needs to be a way for more funding to be added to the rewards plan.
|
||||
|
||||
Having multiple possible rewards plans means it is useful to have rpc calls to get information about them. Hence: rewardslist returns the list of rewards creation txids and rewardsinfo <txid> returns the details about a specific rewards plan.
|
||||
|
||||
A locking transaction sends funds to the rewards CC address, along with a normal (small) tx to the address that the unlock should go to. This allows the validation of the proper unlocking. Also, it is important to make sure only locking transactions are able to be unlocked. Additionally, the minimum time needs to elapse before unlocking is allowed.
|
||||
|
||||
All of these things are done in rewards.cpp, with the validation code being about 200 lines and a total of 700 lines or so. Bigger than faucet, but most of the code is the non-consensus code to create the proper transactions. In order to simplify the validation, specific vin and vout positions are designated to have specific required values:
|
||||
|
||||
createfunding
|
||||
vins.*: normal inputs
|
||||
vout.0: CC vout for funding
|
||||
vout.1: normal marker vout for easy searching
|
||||
vout.2: normal change
|
||||
vout.n-1: opreturn 'F' sbits APR minseconds maxseconds mindeposit
|
||||
|
||||
addfunding
|
||||
vins.*: normal inputs
|
||||
vout.0: CC vout for funding
|
||||
vout.1: normal change
|
||||
vout.n-1: opreturn 'A' sbits fundingtxid
|
||||
|
||||
lock
|
||||
vins.*: normal inputs
|
||||
vout.0: CC vout for locked funds
|
||||
vout.1: normal output to unlock address
|
||||
vout.2: change
|
||||
vout.n-1: opreturn 'L' sbits fundingtxid
|
||||
|
||||
unlock
|
||||
vin.0: locked funds CC vout.0 from lock
|
||||
vin.1+: funding CC vout.0 from 'F' and 'A' and 'U'
|
||||
vout.0: funding CC change
|
||||
vout.1: normal output to unlock address
|
||||
vout.n-1: opreturn 'U' sbits fundingtxid
|
||||
|
||||
It is recommended to create such a vin/vout allocation for each CC contract to make sure that the rpc calls that create the transaction and the validation code have a specific set of constraints that can be checked for.
|
||||
|
||||
Chapter 8 - assets example
|
||||
In some respects the assets CC is the most complex, it was actually the first one that I coded. It is however using a simple model, even for the DEX functions, so while it is quite involved, it does not have the challenge/response complexity of dice.
|
||||
|
||||
There are two major aspects to creating tokens. First is to create and track it, down to every specific satoshi. The second is solving how to implement DEX functions of trading assets.
|
||||
|
||||
The model used is "colored coins". This means that the token creating txid issues the assets as denoted by all the satoshis, so locking 1 COIN issues 100 million tokens. This multiplication will allow creation of plenty of assets. We want to preserve all the tokens created across all allowed operations. The way this is achieved is that all operations attaches the token creation txid in its OP_RETURN, along with the specified operation.
|
||||
|
||||
Ownership of tokens are represented by the colored satoshis in the CC address for the user's pubkey. This allows using the standard utxo system to automatically track ownership of the tokens. This automatic inheritance is one of the big advantages of utxo CC contracts that compensates for the slightly more work needed to implement a CC contract.
|
||||
|
||||
So now we have the standard CC addresss, list and info commands that provide the CC addresses, list of all tokens and info on specific tokens and the ability to create and transfer tokens. Any amount of tokens can be created from 1 to very large numbers and using standard addressbalance, addressutxo type of commands, the details of all assets owned can be determined for a specific pubkey.
|
||||
|
||||
Now we can solve the DEX part of the tokenization, which turns out to be much simpler than initially imagined. We start with bidding for a specific token. Funds for the bid are locked into the global CC address, along with the desired token and price. This creates a bid utxo that is able to be listed via an orderbook rpc call. To fill the bid, a specific bid utxo is spent with the appropriate number of assets and change and updated price for the unfilled amount. if the entire amount is filled, then it wont appear in the orderbook anymore.
|
||||
|
||||
asks work by locking assets along with the required price. Partial fills can be supported and the rpc calls can mask the utxo-ness of the funds/assets needed by automatically gathering the required amount of funds to fill the specific amount.
|
||||
|
||||
With calls to cancel the pending bid or ask, we get a complete set of rpc calls that can support a COIN-centric DEX.
|
||||
|
||||
In the future, it is expected that a token swap rpc can be supported to allow directly swapping one token for another, but at first it is expected that there wont be sufficient volumes for such token to token swaps, so it was left out of the initial implementation.
|
||||
|
||||
With just these rpc calls and associated validation, we get the ability to issue tokens and trade them on a DEX!
|
||||
|
||||
create
|
||||
vin.0: normal input
|
||||
vout.0: issuance assetoshis to CC
|
||||
vout.1: tag sent to normal address of AssetsCCaddress
|
||||
vout.2: normal output for change (if any)
|
||||
vout.n-1: opreturn [EVAL_ASSETS] ['c'] [origpubkey] "<assetname>" "<description>"
|
||||
|
||||
transfer
|
||||
vin.0: normal input
|
||||
vin.1 .. vin.n-1: valid CC outputs
|
||||
vout.0 to n-2: assetoshis output to CC
|
||||
vout.n-2: normal output for change (if any)
|
||||
vout.n-1: opreturn [EVAL_ASSETS] ['t'] [assetid]
|
||||
|
||||
buyoffer:
|
||||
vins.*: normal inputs (bid + change)
|
||||
vout.0: amount of bid to unspendable
|
||||
vout.1: normal output for change (if any)
|
||||
vout.n-1: opreturn [EVAL_ASSETS] ['b'] [assetid] [amount of asset required] [origpubkey]
|
||||
|
||||
cancelbuy:
|
||||
vin.0: normal input
|
||||
vin.1: unspendable.(vout.0 from buyoffer) buyTx.vout[0]
|
||||
vout.0: vin.1 value to original pubkey buyTx.vout[0].nValue -> [origpubkey]
|
||||
vout.1: normal output for change (if any)
|
||||
vout.n-1: opreturn [EVAL_ASSETS] ['o'] [assetid]
|
||||
|
||||
fillbuy:
|
||||
vin.0: normal input
|
||||
vin.1: unspendable.(vout.0 from buyoffer) buyTx.vout[0]
|
||||
vin.2+: valid CC output satisfies buyoffer (*tx.vin[2])->nValue
|
||||
vout.0: remaining amount of bid to unspendable
|
||||
vout.1: vin.1 value to signer of vin.2
|
||||
vout.2: vin.2 assetoshis to original pubkey
|
||||
vout.3: CC output for assetoshis change (if any)
|
||||
vout.4: normal output for change (if any)
|
||||
vout.n-1: opreturn [EVAL_ASSETS] ['B'] [assetid] [remaining asset required] [origpubkey]
|
||||
|
||||
selloffer:
|
||||
vin.0: normal input
|
||||
vin.1+: valid CC output for sale
|
||||
vout.0: vin.1 assetoshis output to CC to unspendable
|
||||
vout.1: CC output for change (if any)
|
||||
vout.2: normal output for change (if any)
|
||||
vout.n-1: opreturn [EVAL_ASSETS] ['s'] [assetid] [amount of native coin required] [origpubkey]
|
||||
|
||||
cancel:
|
||||
vin.0: normal input
|
||||
vin.1: unspendable.(vout.0 from exchange or selloffer) sellTx/exchangeTx.vout[0] inputTx
|
||||
vout.0: vin.1 assetoshis to original pubkey CC sellTx/exchangeTx.vout[0].nValue -> [origpubkey]
|
||||
vout.1: normal output for change (if any)
|
||||
vout.n-1: opreturn [EVAL_ASSETS] ['x'] [assetid]
|
||||
|
||||
fillsell:
|
||||
vin.0: normal input
|
||||
vin.1: unspendable.(vout.0 assetoshis from selloffer) sellTx.vout[0]
|
||||
vin.2+: normal output that satisfies selloffer (*tx.vin[2])->nValue
|
||||
vout.0: remaining assetoshis -> unspendable
|
||||
vout.1: vin.1 assetoshis to signer of vin.2 sellTx.vout[0].nValue -> any
|
||||
vout.2: vin.2 value to original pubkey [origpubkey]
|
||||
vout.3: CC asset for change (if any)
|
||||
vout.4: CC asset2 for change (if any) 'E' only
|
||||
vout.5: normal output for change (if any)
|
||||
vout.n-1: opreturn [EVAL_ASSETS] ['S'] [assetid] [amount of coin still required] [origpubkey]
|
||||
|
||||
Chapter 9 - dice example
|
||||
The dice CC contract is actually more complex in the sequences required than the assets/tokens CC. The reason is the need for realtime response by the dealer node, but also having a way to resolve bets if the dealer node is not online. The dice CC contract shows how to build in such a challenge/response mechanism, which likely will be very useful for many other realtime interactive CC contracts.
|
||||
|
||||
First, let us describe the issues that the dice CC contract needs to solve. Foremost is that it needs to be random and fair. It should also have realtime response and a fallback timeout in case the realtime response doesnt happen. As with the rewards CC contract, multiple dice plans are supported. Each plan can be customized as to the following: minbet, maxbet, maxodds, timeoutblocks
|
||||
|
||||
This allows each plan to control the risk exposure and also advertises to everyone when dicebets expire and a timeout win can be claimed. In event the dealer node does not process a dicebet in time, in order to prevent dealer nodes from simply not responding to dicebets that they lose, a timeout must go to the dicebet player. A short timeframe means that the dealer would need to be running multiple redundant nodes to make sure they can respond in time. If the timeout is set to long, then many players would prefer to use a different dice plan with a shorter timeout.
|
||||
|
||||
Now to describe how to ensure a proper random number that is fair. The method chosen was for the dealer node to create transactions with hash of their entropy in the OP_RETURN. Then the dicebet player would select a specific entropy tx and include their (unhashed) entropy to their OP_RETURN. This allows the dealer node to immediately determine if the dicebet won or lost. If the dicebet included the hash of the bettor entropy, then another step would be needed. However, doing so would allow some timeouts to end with a refund, rather than an automatic win for the dicebet player.
|
||||
|
||||
One additional technique used to keep all required data on the blockchain is the dealer entropy value calculation. The vin0 txid is used as one of the privkeys to calculate a shared secret and then hashed to remove links to the original privkey. This method allows recreating the dealer's entropy value (by the dealer node) given the blockchain itself, which means there is no need for any local storage.
|
||||
|
||||
This allows the dealer node to recreate the unhashed entropy value used and so when the dicebet transaction is seen (in the mempool!), the dealer node can immediately determine if it is a winner or a loser. This is done by creating a dealer hash vs. a bettor hash via:
|
||||
|
||||
dealer hash: SHA256(dealer entropy + bettor entropy)
|
||||
bettor hash: SHA256(bettor entropy + dealer entropy)
|
||||
|
||||
The same values are used, but in different order. The resulting hashes are compared arithmetically for 1:1 bets and the standard industry use is used for the higher odds: https://dicesites.com/provably-fair
|
||||
|
||||
The dealer creates a dice plan and then also needs to create entropy transactions. Each win or loss that creates change also creates entropy transactions by the dealer, but timeout transactions wont as it needs to be created by the dealer node to prevent cheating. The dealer tx are locked into the global dice CC address, as is the dicebet transaction, which selects a specific entropy tx to "roll" against. Then the dicefinish process by the dealer will spend the dicebet outputs either all to itself for a loss, or the winning amount to th dice bettor's address. For dicebets that are not dicefinish'ed by the dealer, anybody is able to do a timeout completion.
|
||||
|
||||
createfunding:
|
||||
vins.*: normal inputs
|
||||
vout.0: CC vout for funding
|
||||
vout.1: owner vout
|
||||
vout.2: dice marker address vout for easy searching
|
||||
vout.3: normal change
|
||||
vout.n-1: opreturn 'F' sbits minbet maxbet maxodds timeoutblocks
|
||||
|
||||
addfunding (entropy):
|
||||
vins.*: normal inputs
|
||||
vout.0: CC vout for locked entropy funds
|
||||
vout.1: tag to owner address for entropy funds
|
||||
vout.2: normal change
|
||||
vout.n-1: opreturn 'E' sbits fundingtxid hentropy
|
||||
|
||||
bet:
|
||||
vin.0: entropy txid from house (must validate vin0 of 'E')
|
||||
vins.1+: normal inputs
|
||||
vout.0: CC vout for locked entropy
|
||||
vout.1: CC vout for locked bet
|
||||
vout.2: tag for bettor's address (txfee + odds)
|
||||
vout.3: change
|
||||
vout.n-1: opreturn 'B' sbits fundingtxid entropy
|
||||
|
||||
loser:
|
||||
vin.0: normal input
|
||||
vin.1: betTx CC vout.0 entropy from bet
|
||||
vin.2: betTx CC vout.1 bet amount from bet
|
||||
vin.3+: funding CC vout.0 from 'F', 'E', 'W', 'L' or 'T'
|
||||
vout.0: funding CC to entropy owner
|
||||
vout.1: tag to owner address for entropy funds
|
||||
vout.2: change to fundingpk
|
||||
vout.n-1: opreturn 'L' sbits fundingtxid hentropy proof
|
||||
|
||||
winner:
|
||||
same as loser, but vout.2 is winnings
|
||||
vout.3: change to fundingpk
|
||||
vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof
|
||||
|
||||
timeout:
|
||||
same as winner, just without hentropy or proof
|
||||
|
||||
WARNING: there is an attack vector that precludes betting any large amounts, it goes as follows:
|
||||
1. do dicebet to get the house entropy revealed
|
||||
2. calculate bettor entropy that would win against the house entropy
|
||||
3. reorg the chain and make a big bet using the winning entropy calculated in 2.
|
||||
|
||||
In order to mitigate this, the disclosure of the house entropy needs to be delayed beyond a reasonable reorg depth (notarization). It is recommended for production dice game with significant amounts of money to use such a delayed disclosure method.
|
||||
|
||||
|
||||
Chapter 10 - channels example
|
||||
It might be hard to believe, but channels CC implements an instant payment mechanism that is secured by dPoW in a way that is backward compatible with the existing wallets, explorers, etc. and channels CC does not require both nodes to be online. Its usecases are all the usecases for Lightning Network, it is just more secure, less expensive and backward compatible! The one aspect which some might consider a downside (and others another benefit) is that all payments are onchain. This means it would increase blockchain size, but the idea is for channels CC to be used on blockchains with relatively lower value coins, so a txfee of 0.0001 is not anything significant.
|
||||
|
||||
Warning: very confusing blockchain reorganization issues described below. Will be confusing to most people
|
||||
|
||||
From a distance, the blockchain is a chain of blocks. One block after the next, each referencing all the prior blocks. Each block containing a group of transactions. Prior to getting into a block, the transactions are broadcast to the network and if it is valid, it enters the memory pool. Each miner then constructs a valid block from these memory pool transactions and when a transaction gets mined (confirmed), it is removed from the memory pool.
|
||||
|
||||
That is the simple version!
|
||||
|
||||
The reality is quite a bit more complex, but the critical aspect is that the blockchain can (and is) reorganized as part of the expected protocol. This can happen even when there is no 51% attack happening and it is important to understand this process in detail, so here goes.
|
||||
|
||||
What happens if two miners find a valid block at the same time? In this case the "same time" means within the time it takes for a block to propagate to the network. When a miner finds a new block, it is broadcast to the network and nodes update and start waiting for the next block. When there are two different (and valid) blocks propagating at the same time, some nodes update with one of the blocks and some the other, lets call it blockA and blockB. Now the nodes will know about both blockA and blockB, but some will consider blockA to be the chaintip and others will consider blockB to be the chaintip.
|
||||
|
||||
This is where it gets confusing. Which is the correct chaintip (latest block?). It turns out that both blockA and blockB are valid at this moment in time. So there are actuall two blockchains. We have what is called a small fork! Now dont worry, the protocol will help us converge to a single chain, but in order to do that, we need the next block.
|
||||
|
||||
Some miners will be mining from blockA and others from blockB. In most all cases, when the next block is found, it wont be at the "same time" again. So we will end up with a chain that is blockA+blockA2 or blockB+blockB2. Here comes the small reorg! Let's assuming blockA2 was found before blockB2, so that means all nodes that had blockB as the chaintip now see a longer chain blockA+blockA2, which trumps blockB. When that happens, it reorgs the chain so it is on blockA+blockA2. To do this properly, all the transactions that were in blockB are put back into the mempool and blockA is added, then blockA2.
|
||||
|
||||
Of course, when blockB2 arrives, the nodes see it but blockB+blockB2 is the same length as blockA+blockA2, so no reorg happens. Since we postulated that blockAs arrived "before" blockB2, that means all nodes are on the same chaintip, including all the miners and the next block found would be blockA3, without any complications.
|
||||
|
||||
Believe it or not, this sort of thing is happening all the time, one all blockchains. The chaintip is a volatile thing and that is why more than one confirmation is needed to avoid the small reorgs invalidating blockhash. However, it is possible for more than just the blockhash to change. When the reorg happens, all the transactions in the block are put back into the mempool and then the new blocks are processed in order. So what happens if one of the inputs to a transaction that happened in blockB, gets spent in blockA2? Based on random utxo allocation by wallets this is not impossible if an address has a lot of activity, but if it is part of a 51% attack, then this remote chance of an utxo being spent becomes a certainity! In fact, that is what a 51% attack is.
|
||||
|
||||
The attack can go much deeper than just one block. For chains that use the longest chain rule, it can go quite deep indeed. So as all the reorged transactions are put back into the mempool, we feel good that it will get confirmed again. Unfortunately, there is no enforcement of a miner needing to mine any specific transaction in the mempool. And the 51% attacker is intent on mining the transaction that spends an already spent utxo in the reorganized chain. it is called a double spend, but in the reorganized chain, it is spent only once. So it is a bit of a misnomer.
|
||||
|
||||
The important thing to understand is that if any transaction has inputs that are signed by a node, it is possible when the chain reorganizes for that transaction to become invalid. This is why dPoW is important as it doesnt strictly use the longest chain rule, but rather the longest notarized chain rule. Once a block is notarized, then it will refuse to reorganize that block (or any block before). So the risk is still there, but only until a notarization. Please see more detailed information about dPoW <here>.
|
||||
|
||||
Given the above, if you are wondering how can it be possible to have a mempool payment be secured by dPoW. Since it is explained how the reorgs can make valid transactions disappear, it seems unlikely any such solution is possible. However, the CC is very powerful and it can make unlikely things possible.
|
||||
|
||||
The following describes how.
|
||||
|
||||
We know that any payment that is utxo based can be invalidated via 51% attack, or even an unlikely but not impossible random utxo allocation from a busy wallet. Which means the payment cant be via a utxo. Since the CC system is utxo based, you might think that it means CC cant solve this. However, CC is very powerful and can implement payments that are not utxo based. But before this non-utxo payment method is explained, first we need to solve the mechanics of payment.
|
||||
|
||||
At a high level, we want to lock funds into a channel, have this lock notarized so it cant be reorganized. Then payments can unlock funds. Additionally, if we are restricting the payment to just one destination, we also need a way for the sender to reclaim the unused funds. So there needs a way for a close channel notification, which when notarized allows the sender to reclaim all funds. After the channel close is notarized, then the only action possible should be a reclaim of sender funds.
|
||||
|
||||
We need to assume that any payment, channel close, reclaim can be reorganized until it is notarized so great care needs to be made that a payment that is made will always be valid. With some allowances for blocks after a channelclose is notarized, we can protect the payments using the logic of "stop accepting payments after a channelclose is seen". It might be that a full notarization of wait time after the channelclose is notarized is needed to provide sufficient time for all the payments to be reprocessed.
|
||||
|
||||
Now we can finally describe the requirements for the CC. The locked funds need to be able to be spent by either the sender or receiver, the former only after sufficient time after a channelclose and the latter only after a payment is seen (not just confirmed, but just seeing it should be enough). The protection from reorgs is that the payment itself reveals a secret that is needed for the payment and only the secret would be needed, so it wont matter what utxo is used. To lock funds into a CC address that can handle this we need a 1of2 CC address, which can accept a signature from either of two pubkeys. The additional CC constraints would be enforced to make sure payments are made until the channel is closed.
|
||||
|
||||
A hashchain has the nice property of being able to encode a lot of secrets with a single hash. You can hash the hash, over and over and the final hash is the public value. By revealing the next to last hash, it can be verified that it hashes to the final hash. There is a restriction that a hashchain needs to be of reasonable maximum depth, say 1000. That means each iteration of the hashchain that is revealed is worth 1/1000th the total channelfunds. In fact, if the 500th hash value is revealed, half the channelfunds are released. this allows 1/1000th resolution that can be released with a single hash value.
|
||||
|
||||
Now we can make the payment based on the hashvalue revealed at a specified depth before the prior released hashchain value. Both the sender and receiver can make a payment to the destination by attaching a hashchain secret. This means even if the sender's payment is reorganized, if the destination has the revealed secret, a replacement payment can be made that is valid. If the destination account isnt monitoring the blockchain, then it wont see the revealed secret, but in this case there shouldnt be value released for the payments that are reorganized. So it would be a case of no harm, no foul. In any event, all the payments end up verifiable on the blockchain to provide verifiability.
|
||||
|
||||
Payments at the speed of the mempool, protected by dPoW!
|
||||
|
||||
RPC calls
|
||||
channelsopen:
|
||||
Used to open channel between two pub keys (sender and receiver). Parameters: destination_pubkey, total_number_of_payments, payment_denomination.
|
||||
Example - channelsopen 03a8fe537de2ace0d9c210b0ff945085c9192c9abf56ea22f22ce7998f289bb7bb 10 10000000
|
||||
channelspayment:
|
||||
Sending payment to receiver. Condition is that the channel open tx is confirmed/notarised. Parameters: open_tx_id, payment_amount, [secret] (optional, used when receiver needs to make a payment which secret has already been revealed by sender).
|
||||
Example - channelspayment b9c141facc8cb71306d0de8e525b3de1450e93e17fc8799c8fda5ed52fd14440 20000000
|
||||
channelsclose:
|
||||
Marking channel as closed. This RPC only creates a tx which says that the channel is closed and will be used in refund RPC to withdraw funds from closed channel. This also notifies receiver that channel fund could be withdrawn, but the payment RPC is still available until all funds are withdrawn. Parameters: open_tx_id.
|
||||
Example - channelsclose b9c141facc8cb71306d0de8e525b3de1450e93e17fc8799c8fda5ed52fd14440
|
||||
channelsrefund:
|
||||
Withdrawing funds back to senders address. Refund can be issued only when channel close tx is confirmed/notarised. Parameters: open_tx_id, close_tx_id
|
||||
Example - channelsrefund b9c141facc8cb71306d0de8e525b3de1450e93e17fc8799c8fda5ed52fd14440 bb0ea34f846247642684c7c541c435b06ee79e47893640e5d2e51023841677fd
|
||||
channelsinfo:
|
||||
Getting info about channels in which the issuer is involved, either as sender or receiver. Call without parameters give the list of available channels. Parameters: [open_tx_id] (optional - used to get info about specific channel)
|
||||
|
||||
VIN/VOUT allocation
|
||||
Open:
|
||||
vin.0: normal input
|
||||
vout.0: CC vout for channel funding on CC1of2 pubkey
|
||||
vout.1: CC vout marker to senders pubKey
|
||||
vout.2: CC vout marker to receiver pubkey
|
||||
vout.n-2: normal change
|
||||
vout.n-1: opreturn - 'O' zerotxid senderspubkey receiverspubkey totalnumberofpayments paymentamount hashchain
|
||||
|
||||
Payment
|
||||
vin.0: normal input
|
||||
vin.1: CC input from channel funding
|
||||
vin.2: CC input from src marker
|
||||
vout.0: CC vout change to channel funding on CC1of2 pubkey
|
||||
vout.1: CC vout marker to senders pubKey
|
||||
vout.2: CC vout marker to receiver pubkey
|
||||
vout.3: normal output of payment amount to receiver pubkey
|
||||
vout.n-2: normal change
|
||||
vout.n-1: opreturn - 'P' opentxid senderspubkey receiverspubkey depth numpayments secret
|
||||
|
||||
Close:
|
||||
vin.0: normal input
|
||||
vin.1: CC input from channel funding
|
||||
vin.2: CC input from src marker
|
||||
vout.0: CC vout for channel funding
|
||||
vout.1: CC vout marker to senders pubKey
|
||||
vout.2: CC vout marker to receiver pubkey
|
||||
vout.n-2: normal change
|
||||
vout.n-1: opreturn - 'C' opentxid senderspubkey receiverspubkey 0 0 0
|
||||
|
||||
Refund:
|
||||
vin.0: normal input
|
||||
vin.1: CC input from channel funding
|
||||
vin.2: CC input from src marker
|
||||
vout.0: CC vout marker to senders pubKey
|
||||
vout.1: CC vout marker to receiver pubKey
|
||||
vout.2: normal output of CC input to senders pubkey
|
||||
vout.n-2: normal change
|
||||
vout.n-1: opreturn - 'R' opentxid senderspubkey receiverspubkey numpayments payment closetxid
|
||||
|
||||
Chapter 11 - oracles example
|
||||
Oracles CC is an example where it ended up being simpler than I first expected, but at the same time a lot more powerful. It is one of the smaller CC, but it enables creation of an arbitrary number of data markets, in a performant way.
|
||||
|
||||
In order to gain the performance, some clever usage of special addresses was needed. It was a bit tricky to generate a special address to keep track of the latest data.
|
||||
|
||||
Let's back up to the beginning. Just what is an oracle? In this context it is something that puts data that is not on the blockchain, onto the blockchain. Since everything other than the transactions and blocks are not in the blockchain, there is a very large universe of data that can be oracle-ized. It can be literally anything, from the obvious like prices to specific results relative to an arbitrary description.
|
||||
|
||||
The most difficult issue about oracles is that they need to be trusted to various degree to provide accurate and timely data. The danger is that if a trusted node is used to write data to the blockchain, it creates a trust point and a single point of attack. Ultimately there is nothing that can ensure only valid data is written to the blockchain, so what is done is to reinforce good behavior via pay per datapoint. However, for critical data, higher level processing is needed that combines multiple data providers into a validated signal.
|
||||
|
||||
At the oracles CC level, it is enough that there is financial incentive to provide good data. Also it is needed to allow multiple vendors for each data that is required and to enable efficient ways to update and query the data.
|
||||
|
||||
The following are the rpc calls:
|
||||
oraclescreate name description format
|
||||
oracleslist
|
||||
oraclesinfo oracletxid
|
||||
oraclesregister oracletxid datafee
|
||||
oraclessubscribe oracletxid publisher amount
|
||||
oraclesdata oracletxid hexstr
|
||||
oraclessamples oracletxid batonutxo num
|
||||
|
||||
The first step is to create a specific data description with oraclescreate, which also defines the format of the binary data. This creates an oracletxid, which is used in the other rpc calls. name and description are just arbitrary strings, with name preferably being a short name used to access the data. The format is a string comprised of a single character per data element:
|
||||
|
||||
's' -> <256 char string
|
||||
'S' -> <65536 char string
|
||||
'd' -> <256 binary data
|
||||
'D' -> <65536 binary data
|
||||
'c' -> 1 byte signed little endian number, 'C' unsigned
|
||||
't' -> 2 byte signed little endian number, 'T' unsigned
|
||||
'i' -> 4 byte signed little endian number, 'I' unsigned
|
||||
'l' -> 8 byte signed little endian number, 'L' unsigned
|
||||
'h' -> 32 byte hash
|
||||
|
||||
For example, if the datapoint is comprised of a 4byte timestamp and an 8byte number the format string would be: "IL"
|
||||
|
||||
oracleslist displays a list of all the oraclestxid and oraclesinfo displays information about the specific oracletxid. Each oracletxid deterministically generates a marker address and a small amount is sent to that address to mark a transaction's relation to the oracltxid.
|
||||
|
||||
{
|
||||
"result": "success",
|
||||
"txid": "4895f631316a649e216153aee7a574bd281686265dc4e8d37597f72353facac3",
|
||||
"name": "BTCUSD",
|
||||
"description": "coindeskpricedata",
|
||||
"format": "L",
|
||||
"marker": "RVqJCSrdBm1gYJZS1h7dgtHioA5TEYzNRk",
|
||||
"registered": [
|
||||
{
|
||||
"publisher": "02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92",
|
||||
"baton": "RKY4zmHJZ5mNtf6tfKE5VMsKoV71Euej3i",
|
||||
"batontxid": "4de10b01242ce1a5e29d5fbb03098b4519976879e05ad0458ef7174ed9127f18",
|
||||
"lifetime": "1.50000000",
|
||||
"funds": "0.01000000",
|
||||
"datafee": "0.01000000"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
A data publisher needs to register a datafee and their pubkey for a specific oracletxid. datafee needs to be at least as big as a txfee. Using oraclesregister the current datafee can be updated so a publisher can adapt to market conditions. Once registered, subscribers can prepay for some number of datapoints to a specific publisher using the oraclessubscribe rpc. At first, it is likely that the publisher would pay themselves to enable the posting of initial data points so the potential subscribers can evaluate the quality and consistency of the data.
|
||||
|
||||
The one final rpc is oraclessamples, which returns the most recent samples of data from a specific publisher. In order to have a performant solution to track all the potential data streams from all the publishers for all the oracletxid, a baton utxo is used. This is an output sent to a specific address and expected to have just a single utxo at any given time to allow for direct lookup. oraclessamples requires a starting txid to use and with each datapoint having the prior batontxid, there is a reverse linked list to traverse the most recent data.
|
||||
|
||||
In order to implement this, the following vin/vout contraints are used:
|
||||
|
||||
create:
|
||||
vins.*: normal inputs
|
||||
vout.0: txfee tag to oracle normal address
|
||||
vout.1: change, if any
|
||||
vout.n-1: opreturn with name and description and format for data
|
||||
|
||||
register:
|
||||
vins.*: normal inputs
|
||||
vout.0: txfee tag to normal marker address
|
||||
vout.1: baton CC utxo
|
||||
vout.2: change, if any
|
||||
vout.n-1: opreturn with oracletxid, pubkey and price per data point
|
||||
|
||||
subscribe:
|
||||
vins.*: normal inputs
|
||||
vout.0: subscription fee to publishers CC address
|
||||
vout.1: change, if any
|
||||
vout.n-1: opreturn with oracletxid, registered provider's pubkey, amount
|
||||
|
||||
data:
|
||||
vin.0: normal input
|
||||
vin.1: baton CC utxo (most of the time)
|
||||
vin.2+: subscription or data vout.0
|
||||
vout.0: change to publishers CC address
|
||||
vout.1: baton CC utxo
|
||||
vout.2: payment for dataprovider
|
||||
vout.3: change, if any
|
||||
vout.n-1: opreturn with oracletxid, prevbatontxid and data in proper format
|
||||
|
||||
The oraclesdata transaction is the most complex as it needs to find and spend the baton utxo, use the correct datafee and spend funds from the locked subscription funds. With the above, the oracles CC is complete and allows the creations of massively parallel data streams from multiple vendors that uses free market feedback via payments, ie. poorly performing providers wont get renewals.
|
||||
|
||||
I expect that at first, the data providers will just be dapp developers deploying a working system including the required data, but its structure allows open market competition. Of course, specific dapps could restrict themselves to using only publishers from a whitelist of pubkeys. The potential usecases for oracles CC is quite varied and limited only by the imagination.
|
||||
|
||||
Chapter 12 - limitless possibilities
|
||||
As can be seen, CC contracts can do a wide range of things and since they are Turing complete, we know that this is true. However, what is more important is the added security gained from using a utxo based system. While in some ways it is more complex to have to deal with utxo, as can be seen by the above examples, it is either solved and made invisible at the rpc level, or actually used as part of the solution.
|
||||
|
||||
Being utxo based, automatically builds in a rate limit to how many tx per block a specific CC contract can do. The state advancing by one transaction at a time is another means that rate limits. Since more utxo can be made available to increase capacity, it actually offers a way for managing load.
|
||||
|
||||
I believe I have made one of the first operational utxo smart contracts, CC or otherwise and hope that there will be many more developers joining forces to create more foundational CC contracts. Feel free to contact me for feedback on the type of CC contract you want to make. I have not documented all my notes and it could well be I already sort of know how to implement what your want your CC contract to do. Just only so many I can actually make time to code and debug.
|
||||
|
||||
Our testing cycle went a lot faster than expected as the bugs found were few and far between. Considering the scope of the assets CC and the realtime response aspects of dice CC, this was quite unexpected. I can only attribute it to the fact that CC validation is just the final validation on top of all the standard bitcoin protocol validations. Not having to worry about double spends is sure a nice luxury, though dont get too complacent about chain rewrites! It is possible to wait for information to be divulged and then reorg the chain to take advantage of this knowledge in a chain which is rewound.
|
||||
|
||||
Yes, blockchains are complicated.
|
||||
|
||||
Chapter 13 - different languages
|
||||
The current codebase is integrated into the komodod codebase, which is C/C++. However, it is possible to use different languages and integrate into the C/C++ as zcash has shown by using the rust language for some parts of the zcashd.
|
||||
|
||||
I think any language that is compiled and can create a linkable library while being able to call and be called by C/C++ functions can be used. If you are able to make such a language binding for a simple CC contract like faucet, this will be good for a 777 KMD bounty. Of course, you need to be the first to submit a properly working pull request.
|
||||
|
||||
|
||||
Chapter 14 - runtime bindings
|
||||
Once build time linking works, then it is one step away from being able to do runtime linking, ie. dynamically linked libraries. There will be some work required to prevent duplication of eval codes and making sure it is a valid version of the CC contract plugin, but these are issues that have been solved before and I dont see any reason they cant be solved for CC contracts.
|
||||
|
||||
This would open up the door for quite an interesting ecosystem of CC plugins that blockchains can subscribe to.
|
||||
|
||||
Chapter 15 - rpc based dapps
|
||||
Ultimately, I expect there to be so many new rpc calls (one set from each CC contract), that virtually any dapp can be made with rpc calls. We are just at the beginning now, but it is just a matter of time when we get there.
|
||||
|
||||
For now, we just need to keep listening to what the market wants as far as dapps go. Then make a new CC contract that enables doing as many of those as possible.
|
||||
|
||||
Repeat...
|
||||
|
||||
Imagine the scope that will exist after a year or two of continuous new CC contracts being created, along with all the rpc based dapps. I have seen some automatic GUI generators and it could be that for most cases, there can be a special GUI that not only create the dapp's GUI, but also all the rpc calls that are needed to make it work the way it is customized.
|
||||
|
||||
This codebase and tools in between the GUI and the rpc level will be a very good area for new initiatives.
|
||||
|
||||
##########
|
||||
|
||||
Conclusion
|
||||
I hope this document has helped you understand what a Komodo utxo based CC contract is and how it is different from the other smart contracts. If you are now able to dive into the cc directory and start making your own CC contract, then I am very happy!
|
||||
|
||||
|
||||
gateways CC
|
||||
gateways CC is the first CC that combines multiple CC into a single one. In order to achieve its goals, both the assets CC and the oracles CC is used, in addition to a dapp that issues regular transactions. This general approach can be used to solve quite a few different use cases, so it is important to understand how a multi-CC solution is put together. There are some tricky issues that only arise when using more than one CC at a time.
|
||||
|
||||
Before the implementation details, first lets understand what the gateways CC does. At a high level it is similar to the old multigateway (from NXT AE 2014), but with improvements. The basic idea is to tokenize other crypto coins (like BTC) and then use the assets CC to transact/swap against the tokenized crypto. By enforcing a 1:1 peg between a specific token and BTC and an automated deposit/withdraw mechanism, it is possible to transact in the virtual BTC without the delay or expensive txfees. Then anybody that ends up having any of the BTC token would be able to withdraw actual BTC by redeeming the token.
|
||||
|
||||
BTC -> deposit to special address -> receive token that represents BTC onchain
|
||||
do onchain transactions with the BTC token
|
||||
anybody who obtains the BTC token can redeem the token and get actual BTC in the withdraw address
|
||||
|
||||
By bringing the operations onchain, it avoids the need for crosschain complications for each trade. The crosschain does still have to happen on the deposit and withdraw, but that is all. There is just one aspect that makes it not fully decentralized, which is the reliance on MofN multisig. However, with N trusted community members and a reasonable M value, it is not expected to be a big barrier. Since all operations are automated, the only trust needed is that M of the N multisig signers are running their nodes with the gateways dapp active and also that M of them wont collude to steal the funds locked in the multisig. In three years of operations, the MGW multigateway didnt have any incident of multisig signer misbehavior and it was only 2of3 multisig.
|
||||
|
||||
How can the gatewaysCC work? First, it needs a dedicated token that can be used to represent the external crypto coin. In order to avoid any issues with misplaced tokens, it is simplest to require that 100% of all the tokens are all locked in the gatewaysCC address. We want to make it so that the only way the tokens can be released from the locked address is when a verified deposit is made. So, we also need a deposit address, which means there needs to be a set of pubkeys that control the deposit address. It turns out, we also need to post merkleroot data from the external coin so that the information is onchain to be able to validate the external deposit. Since we are already trusting the deposit address signers to safekeep the external coins via MofN multisig, trusting them to post the merkleroots doesnt increase the trust footprint needed.
|
||||
|
||||
Now we have all the ingredients needed, a dedicated token, a set of multisig pubkeys and an oracle for merkleroots.
|
||||
|
||||
gatewaysbind tokenid oracletxid coin tokensupply M N pubkey(s)
|
||||
|
||||
With a gatewaysbind, a new gateway is defined. the pubkeys are for the custodians of the multisig funds and they also need to be posting merkleroots to the chain, so the oracle needs to be setup and funded and each of the signers needs to run the oraclefeed dapp. That posts each new merkleroot via oraclesdata and also responds to withdraw requests.
|
||||
|
||||
The MofN pubkeys generates a deposit address and when funds are sent to that address along with a small amount to the claim address. With the txid from this external coin, along with the txproof and the rawtransaction, all is submitted with a gatewaysdeposit. This adds a special baton output which is a gateways CC output to invoke gateways validation and also prevents double claims by using the unspent status of the baton.
|
||||
|
||||
gatewaysdeposit bindtxid height coin cointxid claimvout deposithex proof destpub amount
|
||||
gatewaysclaim bindtxid coin deposittxid destpub amount
|
||||
|
||||
Once the gatewaysdeposit is validated, it can be claimed and now the token is sent to the claim address. A 1:1 pegging of the external crypto to the token is established. And as long as one of the deposit address signers is running the oraclefeed, then the deposit/claim process is fully automatic and under the control of the depositor. Nothing needs to be signed by any other party! Also by using the utxo from the deposittxid, double claims are prevented.
|
||||
|
||||
On the withdraw side, the tokens are sent back to the address where the tokens are locked and this needs to create a redemption right that can only be used once.
|
||||
|
||||
gatewayswithdraw bindtxid coin withdrawpub amount
|
||||
|
||||
|
||||
And with a bit more magic in the oraclefeed, this is achieved. To be continued...
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
// Copyright (c) 2012-2014 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "leveldbwrapper.h"
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <leveldb/cache.h>
|
||||
#include <leveldb/env.h>
|
||||
#include <leveldb/filter_policy.h>
|
||||
#include <memenv.h>
|
||||
|
||||
void HandleError(const leveldb::Status& status)
|
||||
{
|
||||
if (status.ok())
|
||||
return;
|
||||
LogPrintf("%s\n", status.ToString());
|
||||
if (status.IsCorruption())
|
||||
throw leveldb_error("Database corrupted");
|
||||
if (status.IsIOError())
|
||||
throw leveldb_error("Database I/O error");
|
||||
if (status.IsNotFound())
|
||||
throw leveldb_error("Database entry missing");
|
||||
throw leveldb_error("Unknown database error");
|
||||
}
|
||||
|
||||
static leveldb::Options GetOptions(size_t nCacheSize, bool compression, int maxOpenFiles)
|
||||
{
|
||||
leveldb::Options options;
|
||||
options.block_cache = leveldb::NewLRUCache(nCacheSize / 2);
|
||||
options.write_buffer_size = nCacheSize / 4; // up to two write buffers may be held in memory simultaneously
|
||||
options.filter_policy = leveldb::NewBloomFilterPolicy(10);
|
||||
options.compression = compression ? leveldb::kSnappyCompression : leveldb::kNoCompression;
|
||||
options.max_open_files = maxOpenFiles;
|
||||
if (leveldb::kMajorVersion > 1 || (leveldb::kMajorVersion == 1 && leveldb::kMinorVersion >= 16)) {
|
||||
// LevelDB versions before 1.16 consider short writes to be corruption. Only trigger error
|
||||
// on corruption in later versions.
|
||||
options.paranoid_checks = true;
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
CLevelDBWrapper::CLevelDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, bool fMemory, bool fWipe, bool compression, int maxOpenFiles)
|
||||
{
|
||||
penv = NULL;
|
||||
readoptions.verify_checksums = true;
|
||||
iteroptions.verify_checksums = true;
|
||||
iteroptions.fill_cache = false;
|
||||
syncoptions.sync = true;
|
||||
options = GetOptions(nCacheSize, compression, maxOpenFiles);
|
||||
options.create_if_missing = true;
|
||||
if (fMemory) {
|
||||
penv = leveldb::NewMemEnv(leveldb::Env::Default());
|
||||
options.env = penv;
|
||||
} else {
|
||||
if (fWipe) {
|
||||
LogPrintf("Wiping LevelDB in %s\n", path.string());
|
||||
leveldb::Status result = leveldb::DestroyDB(path.string(), options);
|
||||
HandleError(result);
|
||||
}
|
||||
TryCreateDirectory(path);
|
||||
LogPrintf("Opening LevelDB in %s\n", path.string());
|
||||
}
|
||||
leveldb::Status status = leveldb::DB::Open(options, path.string(), &pdb);
|
||||
HandleError(status);
|
||||
LogPrintf("Opened LevelDB successfully\n");
|
||||
}
|
||||
|
||||
CLevelDBWrapper::~CLevelDBWrapper()
|
||||
{
|
||||
delete pdb;
|
||||
pdb = NULL;
|
||||
delete options.filter_policy;
|
||||
options.filter_policy = NULL;
|
||||
delete options.block_cache;
|
||||
options.block_cache = NULL;
|
||||
delete penv;
|
||||
options.env = NULL;
|
||||
}
|
||||
|
||||
bool CLevelDBWrapper::WriteBatch(CLevelDBBatch& batch, bool fSync)
|
||||
{
|
||||
leveldb::Status status = pdb->Write(fSync ? syncoptions : writeoptions, &batch.batch);
|
||||
HandleError(status);
|
||||
return true;
|
||||
}
|
||||
@@ -1,173 +0,0 @@
|
||||
// Copyright (c) 2012-2014 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_LEVELDBWRAPPER_H
|
||||
#define BITCOIN_LEVELDBWRAPPER_H
|
||||
|
||||
#include "clientversion.h"
|
||||
#include "serialize.h"
|
||||
#include "streams.h"
|
||||
#include "util.h"
|
||||
#include "version.h"
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include <leveldb/db.h>
|
||||
#include <leveldb/write_batch.h>
|
||||
|
||||
class leveldb_error : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
leveldb_error(const std::string& msg) : std::runtime_error(msg) {}
|
||||
};
|
||||
|
||||
void HandleError(const leveldb::Status& status);
|
||||
|
||||
/** Batch of changes queued to be written to a CLevelDBWrapper */
|
||||
class CLevelDBBatch
|
||||
{
|
||||
friend class CLevelDBWrapper;
|
||||
|
||||
private:
|
||||
leveldb::WriteBatch batch;
|
||||
|
||||
public:
|
||||
template <typename K, typename V>
|
||||
void Write(const K& key, const V& value)
|
||||
{
|
||||
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
|
||||
ssKey.reserve(ssKey.GetSerializeSize(key));
|
||||
ssKey << key;
|
||||
leveldb::Slice slKey(&ssKey[0], ssKey.size());
|
||||
|
||||
CDataStream ssValue(SER_DISK, CLIENT_VERSION);
|
||||
ssValue.reserve(ssValue.GetSerializeSize(value));
|
||||
ssValue << value;
|
||||
leveldb::Slice slValue(&ssValue[0], ssValue.size());
|
||||
|
||||
batch.Put(slKey, slValue);
|
||||
}
|
||||
|
||||
template <typename K>
|
||||
void Erase(const K& key)
|
||||
{
|
||||
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
|
||||
ssKey.reserve(ssKey.GetSerializeSize(key));
|
||||
ssKey << key;
|
||||
leveldb::Slice slKey(&ssKey[0], ssKey.size());
|
||||
|
||||
batch.Delete(slKey);
|
||||
}
|
||||
};
|
||||
|
||||
class CLevelDBWrapper
|
||||
{
|
||||
private:
|
||||
//! custom environment this database is using (may be NULL in case of default environment)
|
||||
leveldb::Env* penv;
|
||||
|
||||
//! database options used
|
||||
leveldb::Options options;
|
||||
|
||||
//! options used when reading from the database
|
||||
leveldb::ReadOptions readoptions;
|
||||
|
||||
//! options used when iterating over values of the database
|
||||
leveldb::ReadOptions iteroptions;
|
||||
|
||||
//! options used when writing to the database
|
||||
leveldb::WriteOptions writeoptions;
|
||||
|
||||
//! options used when sync writing to the database
|
||||
leveldb::WriteOptions syncoptions;
|
||||
|
||||
//! the database itself
|
||||
leveldb::DB* pdb;
|
||||
|
||||
public:
|
||||
CLevelDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, bool fMemory = false, bool fWipe = false, bool compression = false, int maxOpenFiles = 64);
|
||||
~CLevelDBWrapper();
|
||||
|
||||
template <typename K, typename V>
|
||||
bool Read(const K& key, V& value) const
|
||||
{
|
||||
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
|
||||
ssKey.reserve(ssKey.GetSerializeSize(key));
|
||||
ssKey << key;
|
||||
leveldb::Slice slKey(&ssKey[0], ssKey.size());
|
||||
|
||||
std::string strValue;
|
||||
leveldb::Status status = pdb->Get(readoptions, slKey, &strValue);
|
||||
if (!status.ok()) {
|
||||
if (status.IsNotFound())
|
||||
return false;
|
||||
LogPrintf("LevelDB read failure: %s\n", status.ToString());
|
||||
HandleError(status);
|
||||
}
|
||||
try {
|
||||
CDataStream ssValue(strValue.data(), strValue.data() + strValue.size(), SER_DISK, CLIENT_VERSION);
|
||||
ssValue >> value;
|
||||
} catch (const std::exception&) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename K, typename V>
|
||||
bool Write(const K& key, const V& value, bool fSync = false)
|
||||
{
|
||||
CLevelDBBatch batch;
|
||||
batch.Write(key, value);
|
||||
return WriteBatch(batch, fSync);
|
||||
}
|
||||
|
||||
template <typename K>
|
||||
bool Exists(const K& key) const
|
||||
{
|
||||
CDataStream ssKey(SER_DISK, CLIENT_VERSION);
|
||||
ssKey.reserve(ssKey.GetSerializeSize(key));
|
||||
ssKey << key;
|
||||
leveldb::Slice slKey(&ssKey[0], ssKey.size());
|
||||
|
||||
std::string strValue;
|
||||
leveldb::Status status = pdb->Get(readoptions, slKey, &strValue);
|
||||
if (!status.ok()) {
|
||||
if (status.IsNotFound())
|
||||
return false;
|
||||
LogPrintf("LevelDB read failure: %s\n", status.ToString());
|
||||
HandleError(status);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename K>
|
||||
bool Erase(const K& key, bool fSync = false)
|
||||
{
|
||||
CLevelDBBatch batch;
|
||||
batch.Erase(key);
|
||||
return WriteBatch(batch, fSync);
|
||||
}
|
||||
|
||||
bool WriteBatch(CLevelDBBatch& batch, bool fSync = false);
|
||||
|
||||
// not available for LevelDB; provide for compatibility with BDB
|
||||
bool Flush()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Sync()
|
||||
{
|
||||
CLevelDBBatch batch;
|
||||
return WriteBatch(batch, true);
|
||||
}
|
||||
|
||||
// not exactly clean encapsulation, but it's easiest for now
|
||||
leveldb::Iterator* NewIterator()
|
||||
{
|
||||
return pdb->NewIterator(iteroptions);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // BITCOIN_LEVELDBWRAPPER_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,208 +0,0 @@
|
||||
// Copyright (c) 2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2014 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "rpcclient.h"
|
||||
|
||||
#include "rpcprotocol.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <set>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <univalue.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class CRPCConvertParam
|
||||
{
|
||||
public:
|
||||
std::string methodName; //! method whose params want conversion
|
||||
int paramIdx; //! 0-based idx of param to convert
|
||||
};
|
||||
|
||||
static const CRPCConvertParam vRPCConvertParams[] =
|
||||
{
|
||||
{ "stop", 0 },
|
||||
{ "setmocktime", 0 },
|
||||
{ "getaddednodeinfo", 0 },
|
||||
{ "setgenerate", 0 },
|
||||
{ "setgenerate", 1 },
|
||||
{ "generate", 0 },
|
||||
{ "getnetworkhashps", 0 },
|
||||
{ "getnetworkhashps", 1 },
|
||||
{ "sendtoaddress", 1 },
|
||||
{ "sendtoaddress", 4 },
|
||||
{ "settxfee", 0 },
|
||||
{ "getreceivedbyaddress", 1 },
|
||||
{ "getreceivedbyaccount", 1 },
|
||||
{ "listreceivedbyaddress", 0 },
|
||||
{ "listreceivedbyaddress", 1 },
|
||||
{ "listreceivedbyaddress", 2 },
|
||||
{ "listreceivedbyaccount", 0 },
|
||||
{ "listreceivedbyaccount", 1 },
|
||||
{ "listreceivedbyaccount", 2 },
|
||||
{ "getbalance", 1 },
|
||||
{ "getbalance", 2 },
|
||||
{ "getblockhash", 0 },
|
||||
{ "move", 2 },
|
||||
{ "move", 3 },
|
||||
{ "sendfrom", 2 },
|
||||
{ "sendfrom", 3 },
|
||||
{ "listtransactions", 1 },
|
||||
{ "listtransactions", 2 },
|
||||
{ "listtransactions", 3 },
|
||||
{ "listaccounts", 0 },
|
||||
{ "listaccounts", 1 },
|
||||
{ "walletpassphrase", 1 },
|
||||
{ "getblocktemplate", 0 },
|
||||
{ "listsinceblock", 1 },
|
||||
{ "listsinceblock", 2 },
|
||||
{ "sendmany", 1 },
|
||||
{ "sendmany", 2 },
|
||||
{ "sendmany", 4 },
|
||||
{ "addmultisigaddress", 0 },
|
||||
{ "addmultisigaddress", 1 },
|
||||
{ "createmultisig", 0 },
|
||||
{ "createmultisig", 1 },
|
||||
{ "listunspent", 0 },
|
||||
{ "listunspent", 1 },
|
||||
{ "listunspent", 2 },
|
||||
{ "getblock", 1 },
|
||||
{ "getblockheader", 1 },
|
||||
{ "gettransaction", 1 },
|
||||
{ "getrawtransaction", 1 },
|
||||
{ "createrawtransaction", 0 },
|
||||
{ "createrawtransaction", 1 },
|
||||
{ "signrawtransaction", 1 },
|
||||
{ "signrawtransaction", 2 },
|
||||
{ "sendrawtransaction", 1 },
|
||||
{ "fundrawtransaction", 1 },
|
||||
{ "gettxout", 1 },
|
||||
{ "gettxout", 2 },
|
||||
{ "gettxoutproof", 0 },
|
||||
{ "lockunspent", 0 },
|
||||
{ "lockunspent", 1 },
|
||||
{ "importprivkey", 2 },
|
||||
{ "importaddress", 2 },
|
||||
{ "verifychain", 0 },
|
||||
{ "verifychain", 1 },
|
||||
{ "keypoolrefill", 0 },
|
||||
{ "getrawmempool", 0 },
|
||||
{ "estimatefee", 0 },
|
||||
{ "estimatepriority", 0 },
|
||||
{ "prioritisetransaction", 1 },
|
||||
{ "prioritisetransaction", 2 },
|
||||
{ "setban", 2 },
|
||||
{ "setban", 3 },
|
||||
{ "getblockhashes", 0 },
|
||||
{ "getblockhashes", 1 },
|
||||
{ "getblockhashes", 2 },
|
||||
{ "getspentinfo", 0},
|
||||
{ "getaddresstxids", 0},
|
||||
{ "getaddressbalance", 0},
|
||||
{ "getaddressdeltas", 0},
|
||||
{ "getaddressutxos", 0},
|
||||
{ "getaddressmempool", 0},
|
||||
{ "zcrawjoinsplit", 1 },
|
||||
{ "zcrawjoinsplit", 2 },
|
||||
{ "zcrawjoinsplit", 3 },
|
||||
{ "zcrawjoinsplit", 4 },
|
||||
{ "zcbenchmark", 1 },
|
||||
{ "zcbenchmark", 2 },
|
||||
{ "getblocksubsidy", 0},
|
||||
{ "z_listaddresses", 0},
|
||||
{ "z_listreceivedbyaddress", 1},
|
||||
{ "z_getbalance", 1},
|
||||
{ "z_gettotalbalance", 0},
|
||||
{ "z_gettotalbalance", 1},
|
||||
{ "z_gettotalbalance", 2},
|
||||
{ "z_mergetoaddress", 0},
|
||||
{ "z_mergetoaddress", 2},
|
||||
{ "z_mergetoaddress", 3},
|
||||
{ "z_mergetoaddress", 4},
|
||||
{ "z_sendmany", 1},
|
||||
{ "z_sendmany", 2},
|
||||
{ "z_sendmany", 3},
|
||||
{ "z_shieldcoinbase", 2},
|
||||
{ "z_shieldcoinbase", 3},
|
||||
{ "z_getoperationstatus", 0},
|
||||
{ "z_getoperationresult", 0},
|
||||
{ "z_importkey", 1 },
|
||||
{ "paxprice", 4 },
|
||||
{ "paxprices", 3 },
|
||||
{ "paxpending", 0 },
|
||||
{ "notaries", 2 },
|
||||
{ "minerids", 1 },
|
||||
{ "kvsearch", 1 },
|
||||
{ "kvupdate", 4 },
|
||||
{ "z_importkey", 2 },
|
||||
{ "z_importviewingkey", 2 },
|
||||
{ "z_getpaymentdisclosure", 1},
|
||||
{ "z_getpaymentdisclosure", 2},
|
||||
// crosschain
|
||||
{ "assetchainproof", 1},
|
||||
{ "crosschainproof", 1},
|
||||
{ "getproofroot", 2},
|
||||
{ "height_MoM", 1},
|
||||
{ "calc_MoM", 2},
|
||||
};
|
||||
|
||||
class CRPCConvertTable
|
||||
{
|
||||
private:
|
||||
std::set<std::pair<std::string, int> > members;
|
||||
|
||||
public:
|
||||
CRPCConvertTable();
|
||||
|
||||
bool convert(const std::string& method, int idx) {
|
||||
return (members.count(std::make_pair(method, idx)) > 0);
|
||||
}
|
||||
};
|
||||
|
||||
CRPCConvertTable::CRPCConvertTable()
|
||||
{
|
||||
const unsigned int n_elem =
|
||||
(sizeof(vRPCConvertParams) / sizeof(vRPCConvertParams[0]));
|
||||
|
||||
for (unsigned int i = 0; i < n_elem; i++) {
|
||||
members.insert(std::make_pair(vRPCConvertParams[i].methodName,
|
||||
vRPCConvertParams[i].paramIdx));
|
||||
}
|
||||
}
|
||||
|
||||
static CRPCConvertTable rpcCvtTable;
|
||||
|
||||
/** Non-RFC4627 JSON parser, accepts internal values (such as numbers, true, false, null)
|
||||
* as well as objects and arrays.
|
||||
*/
|
||||
UniValue ParseNonRFCJSONValue(const std::string& strVal)
|
||||
{
|
||||
UniValue jVal;
|
||||
if (!jVal.read(std::string("[")+strVal+std::string("]")) ||
|
||||
!jVal.isArray() || jVal.size()!=1)
|
||||
throw runtime_error(string("Error JSON:")+strVal);
|
||||
return jVal[0];
|
||||
}
|
||||
|
||||
/** Convert strings to command-specific RPC representation */
|
||||
UniValue RPCConvertValues(const std::string &strMethod, const std::vector<std::string> &strParams)
|
||||
{
|
||||
UniValue params(UniValue::VARR);
|
||||
|
||||
for (unsigned int idx = 0; idx < strParams.size(); idx++) {
|
||||
const std::string& strVal = strParams[idx];
|
||||
if (!rpcCvtTable.convert(strMethod, idx)) {
|
||||
// insert string value directly
|
||||
params.push_back(strVal);
|
||||
} else {
|
||||
// parse string as JSON, insert bool/number/object/etc. value
|
||||
params.push_back(ParseNonRFCJSONValue(strVal));
|
||||
}
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
// Copyright (c) 2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2014 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_RPCCLIENT_H
|
||||
#define BITCOIN_RPCCLIENT_H
|
||||
|
||||
#include <univalue.h>
|
||||
|
||||
UniValue RPCConvertValues(const std::string& strMethod, const std::vector<std::string>& strParams);
|
||||
/** Non-RFC4627 JSON parser, accepts internal values (such as numbers, true, false, null)
|
||||
* as well as objects and arrays.
|
||||
*/
|
||||
UniValue ParseNonRFCJSONValue(const std::string& strVal);
|
||||
|
||||
#endif // BITCOIN_RPCCLIENT_H
|
||||
@@ -1,308 +0,0 @@
|
||||
#include "amount.h"
|
||||
#include "chain.h"
|
||||
#include "chainparams.h"
|
||||
#include "checkpoints.h"
|
||||
#include "crosschain.h"
|
||||
#include "notarisationdb.h"
|
||||
#include "importcoin.h"
|
||||
#include "base58.h"
|
||||
#include "consensus/validation.h"
|
||||
#include "cc/eval.h"
|
||||
#include "cc/utils.h"
|
||||
#include "main.h"
|
||||
#include "primitives/transaction.h"
|
||||
#include "rpcserver.h"
|
||||
#include "sync.h"
|
||||
#include "util.h"
|
||||
#include "script/script.h"
|
||||
#include "script/script_error.h"
|
||||
#include "script/sign.h"
|
||||
#include "script/standard.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <univalue.h>
|
||||
#include <regex>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
int32_t komodo_MoM(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight,uint256 *MoMoMp,int32_t *MoMoMoffsetp,int32_t *MoMoMdepthp,int32_t *kmdstartip,int32_t *kmdendip);
|
||||
int32_t komodo_MoMoMdata(char *hexstr,int32_t hexsize,struct komodo_ccdataMoMoM *mdata,char *symbol,int32_t kmdheight,int32_t notarized_height);
|
||||
struct komodo_ccdata_entry *komodo_allMoMs(int32_t *nump,uint256 *MoMoMp,int32_t kmdstarti,int32_t kmdendi);
|
||||
uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth);
|
||||
|
||||
|
||||
UniValue assetchainproof(const UniValue& params, bool fHelp)
|
||||
{
|
||||
uint256 hash;
|
||||
|
||||
// parse params and get notarisation data for tx
|
||||
if ( fHelp || params.size() != 1)
|
||||
throw runtime_error("assetchainproof needs a txid");
|
||||
|
||||
hash = uint256S(params[0].get_str());
|
||||
|
||||
auto proof = GetAssetchainProof(hash);
|
||||
auto proofData = E_MARSHAL(ss << proof);
|
||||
return HexStr(proofData);
|
||||
}
|
||||
|
||||
|
||||
UniValue crosschainproof(const UniValue& params, bool fHelp)
|
||||
{
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
//fprintf(stderr,"crosschainproof needs to be implemented\n");
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
||||
UniValue height_MoM(const UniValue& params, bool fHelp)
|
||||
{
|
||||
int32_t height,depth,notarized_height,MoMoMdepth,MoMoMoffset,kmdstarti,kmdendi; uint256 MoM,MoMoM,kmdtxid; uint32_t timestamp = 0; UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR);
|
||||
if ( fHelp || params.size() != 1 )
|
||||
throw runtime_error("height_MoM height\n");
|
||||
LOCK(cs_main);
|
||||
height = atoi(params[0].get_str().c_str());
|
||||
if ( height <= 0 )
|
||||
{
|
||||
if ( chainActive.Tip() == 0 )
|
||||
{
|
||||
ret.push_back(Pair("error",(char *)"no active chain yet"));
|
||||
return(ret);
|
||||
}
|
||||
height = chainActive.Tip()->nHeight;
|
||||
}
|
||||
//fprintf(stderr,"height_MoM height.%d\n",height);
|
||||
depth = komodo_MoM(¬arized_height,&MoM,&kmdtxid,height,&MoMoM,&MoMoMoffset,&MoMoMdepth,&kmdstarti,&kmdendi);
|
||||
ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL)));
|
||||
ret.push_back(Pair("height",height));
|
||||
ret.push_back(Pair("timestamp",(uint64_t)timestamp));
|
||||
if ( depth > 0 )
|
||||
{
|
||||
ret.push_back(Pair("depth",depth));
|
||||
ret.push_back(Pair("notarized_height",notarized_height));
|
||||
ret.push_back(Pair("MoM",MoM.GetHex()));
|
||||
ret.push_back(Pair("kmdtxid",kmdtxid.GetHex()));
|
||||
if ( ASSETCHAINS_SYMBOL[0] != 0 )
|
||||
{
|
||||
ret.push_back(Pair("MoMoM",MoMoM.GetHex()));
|
||||
ret.push_back(Pair("MoMoMoffset",MoMoMoffset));
|
||||
ret.push_back(Pair("MoMoMdepth",MoMoMdepth));
|
||||
ret.push_back(Pair("kmdstarti",kmdstarti));
|
||||
ret.push_back(Pair("kmdendi",kmdendi));
|
||||
}
|
||||
} else ret.push_back(Pair("error",(char *)"no MoM for height"));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
UniValue MoMoMdata(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if ( fHelp || params.size() != 3 )
|
||||
throw runtime_error("MoMoMdata symbol kmdheight ccid\n");
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
char* symbol = (char *)params[0].get_str().c_str();
|
||||
int kmdheight = atoi(params[1].get_str().c_str());
|
||||
uint32_t ccid = atoi(params[2].get_str().c_str());
|
||||
ret.push_back(Pair("coin",symbol));
|
||||
ret.push_back(Pair("kmdheight",kmdheight));
|
||||
ret.push_back(Pair("ccid", (int) ccid));
|
||||
|
||||
uint256 destNotarisationTxid;
|
||||
std::vector<uint256> moms;
|
||||
uint256 MoMoM = CalculateProofRoot(symbol, ccid, kmdheight, moms, destNotarisationTxid);
|
||||
|
||||
UniValue valMoms(UniValue::VARR);
|
||||
for (int i=0; i<moms.size(); i++) valMoms.push_back(moms[i].GetHex());
|
||||
ret.push_back(Pair("MoMs", valMoms));
|
||||
ret.push_back(Pair("notarization_hash", destNotarisationTxid.GetHex()));
|
||||
ret.push_back(Pair("MoMoM", MoMoM.GetHex()));
|
||||
auto vmomomdata = E_MARSHAL(ss << MoMoM; ss << ((uint32_t)0));
|
||||
ret.push_back(Pair("data", HexStr(vmomomdata)));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
UniValue calc_MoM(const UniValue& params, bool fHelp)
|
||||
{
|
||||
int32_t height,MoMdepth; uint256 MoM; UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR);
|
||||
if ( fHelp || params.size() != 2 )
|
||||
throw runtime_error("calc_MoM height MoMdepth\n");
|
||||
LOCK(cs_main);
|
||||
height = atoi(params[0].get_str().c_str());
|
||||
MoMdepth = atoi(params[1].get_str().c_str());
|
||||
if ( height <= 0 || MoMdepth <= 0 || MoMdepth >= height )
|
||||
throw runtime_error("calc_MoM illegal height or MoMdepth\n");
|
||||
//fprintf(stderr,"height_MoM height.%d\n",height);
|
||||
MoM = komodo_calcMoM(height,MoMdepth);
|
||||
ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL)));
|
||||
ret.push_back(Pair("height",height));
|
||||
ret.push_back(Pair("MoMdepth",MoMdepth));
|
||||
ret.push_back(Pair("MoM",MoM.GetHex()));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
UniValue migrate_converttoexport(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 3)
|
||||
throw runtime_error(
|
||||
"migrate_converttoexport rawTx dest_symbol export_amount\n"
|
||||
"\nConvert a raw transaction to a cross-chain export.\n"
|
||||
"If neccesary, the transaction should be funded using fundrawtransaction.\n"
|
||||
"Finally, the transaction should be signed using signrawtransaction\n"
|
||||
"The finished export transaction, plus the payouts, should be passed to "
|
||||
"the \"migrate_createimporttransaction\" method on a KMD node to get the corresponding "
|
||||
"import transaction.\n"
|
||||
);
|
||||
|
||||
if (ASSETCHAINS_CC < KOMODO_FIRSTFUNGIBLEID)
|
||||
throw runtime_error("-ac_cc < KOMODO_FIRSTFUNGIBLEID");
|
||||
|
||||
if (ASSETCHAINS_SYMBOL[0] == 0)
|
||||
throw runtime_error("Must be called on assetchain");
|
||||
|
||||
vector<uint8_t> txData(ParseHexV(params[0], "argument 1"));
|
||||
CMutableTransaction tx;
|
||||
if (!E_UNMARSHAL(txData, ss >> tx))
|
||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
|
||||
|
||||
string targetSymbol = params[1].get_str();
|
||||
if (targetSymbol.size() == 0 || targetSymbol.size() > 32)
|
||||
throw runtime_error("targetSymbol length must be >0 and <=32");
|
||||
|
||||
CAmount burnAmount = AmountFromValue(params[2]);
|
||||
if (burnAmount <= 0)
|
||||
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for export");
|
||||
{
|
||||
CAmount needed = 0;
|
||||
for (int i=0; i<tx.vout.size(); i++) needed += tx.vout[i].nValue;
|
||||
if (burnAmount < needed)
|
||||
throw runtime_error("export_amount too small");
|
||||
}
|
||||
|
||||
CTxOut burnOut = MakeBurnOutput(burnAmount, ASSETCHAINS_CC, targetSymbol, tx.vout);
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
ret.push_back(Pair("payouts", HexStr(E_MARSHAL(ss << tx.vout))));
|
||||
tx.vout.clear();
|
||||
tx.vout.push_back(burnOut);
|
||||
ret.push_back(Pair("exportTx", HexStr(E_MARSHAL(ss << tx))));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* The process to migrate funds
|
||||
*
|
||||
* Create a transaction on assetchain:
|
||||
*
|
||||
* generaterawtransaction
|
||||
* migrate_converttoexport
|
||||
* fundrawtransaction
|
||||
* signrawtransaction
|
||||
*
|
||||
* migrate_createimportransaction
|
||||
* migrate_completeimporttransaction
|
||||
*/
|
||||
|
||||
UniValue migrate_createimporttransaction(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 2)
|
||||
throw runtime_error("migrate_createimporttransaction burnTx payouts\n\n"
|
||||
"Create an importTx given a burnTx and the corresponding payouts, hex encoded");
|
||||
|
||||
if (ASSETCHAINS_CC < KOMODO_FIRSTFUNGIBLEID)
|
||||
throw runtime_error("-ac_cc < KOMODO_FIRSTFUNGIBLEID");
|
||||
|
||||
if (ASSETCHAINS_SYMBOL[0] == 0)
|
||||
throw runtime_error("Must be called on assetchain");
|
||||
|
||||
vector<uint8_t> txData(ParseHexV(params[0], "argument 1"));
|
||||
|
||||
CTransaction burnTx;
|
||||
if (!E_UNMARSHAL(txData, ss >> burnTx))
|
||||
throw runtime_error("Couldn't parse burnTx");
|
||||
|
||||
|
||||
vector<CTxOut> payouts;
|
||||
if (!E_UNMARSHAL(ParseHexV(params[1], "argument 2"), ss >> payouts))
|
||||
throw runtime_error("Couldn't parse payouts");
|
||||
|
||||
uint256 txid = burnTx.GetHash();
|
||||
TxProof proof = GetAssetchainProof(burnTx.GetHash());
|
||||
|
||||
CTransaction importTx = MakeImportCoinTransaction(proof, burnTx, payouts);
|
||||
return HexStr(E_MARSHAL(ss << importTx));
|
||||
}
|
||||
|
||||
|
||||
UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 1)
|
||||
throw runtime_error("migrate_completeimporttransaction importTx\n\n"
|
||||
"Takes a cross chain import tx with proof generated on assetchain "
|
||||
"and extends proof to target chain proof root");
|
||||
|
||||
if (ASSETCHAINS_SYMBOL[0] != 0)
|
||||
throw runtime_error("Must be called on KMD");
|
||||
|
||||
CTransaction importTx;
|
||||
if (!E_UNMARSHAL(ParseHexV(params[0], "argument 1"), ss >> importTx))
|
||||
throw runtime_error("Couldn't parse importTx");
|
||||
|
||||
CompleteImportTransaction(importTx);
|
||||
|
||||
return HexStr(E_MARSHAL(ss << importTx));
|
||||
}
|
||||
|
||||
|
||||
UniValue getNotarisationsForBlock(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 1)
|
||||
throw runtime_error("getNotarisationsForBlock blockHash\n\n"
|
||||
"Takes a block hash and returns notarisation transactions "
|
||||
"within the block");
|
||||
|
||||
uint256 blockHash = uint256S(params[0].get_str());
|
||||
|
||||
NotarisationsInBlock nibs;
|
||||
GetBlockNotarisations(blockHash, nibs);
|
||||
UniValue out(UniValue::VARR);
|
||||
BOOST_FOREACH(const Notarisation& n, nibs)
|
||||
{
|
||||
UniValue item(UniValue::VARR);
|
||||
item.push_back(n.first.GetHex());
|
||||
item.push_back(HexStr(E_MARSHAL(ss << n.second)));
|
||||
out.push_back(item);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
UniValue scanNotarisationsDB(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() < 2 || params.size() > 3)
|
||||
throw runtime_error("scanNotarisationsDB blockHeight symbol [blocksLimit=1440]\n\n"
|
||||
"Scans notarisationsdb backwards from height for a notarisation"
|
||||
" of given symbol");
|
||||
int height = atoi(params[0].get_str().c_str());
|
||||
std::string symbol = params[1].get_str().c_str();
|
||||
|
||||
int limit = 1440;
|
||||
if (params.size() > 2) {
|
||||
limit = atoi(params[2].get_str().c_str());
|
||||
}
|
||||
|
||||
if (height == 0) {
|
||||
height = chainActive.Height();
|
||||
}
|
||||
|
||||
Notarisation nota;
|
||||
int matchedHeight = ScanNotarisationsDB(height, symbol, limit, nota);
|
||||
if (!matchedHeight) return NullUniValue;
|
||||
UniValue out(UniValue::VOBJ);
|
||||
out.pushKV("height", matchedHeight);
|
||||
out.pushKV("hash", nota.first.GetHex());
|
||||
out.pushKV("opreturn", HexStr(E_MARSHAL(ss << nota.second)));
|
||||
return out;
|
||||
}
|
||||
@@ -1,932 +0,0 @@
|
||||
// Copyright (c) 2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2014 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "amount.h"
|
||||
#include "chainparams.h"
|
||||
#include "consensus/consensus.h"
|
||||
#include "consensus/validation.h"
|
||||
#include "core_io.h"
|
||||
#ifdef ENABLE_MINING
|
||||
#include "crypto/equihash.h"
|
||||
#endif
|
||||
#include "init.h"
|
||||
#include "main.h"
|
||||
#include "metrics.h"
|
||||
#include "miner.h"
|
||||
#include "net.h"
|
||||
#include "pow.h"
|
||||
#include "rpcserver.h"
|
||||
#include "util.h"
|
||||
#include "validationinterface.h"
|
||||
#ifdef ENABLE_WALLET
|
||||
#include "wallet/wallet.h"
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <boost/assign/list_of.hpp>
|
||||
|
||||
#include <univalue.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
extern uint64_t ASSETCHAINS_STAKED;
|
||||
extern int32_t KOMODO_MININGTHREADS;
|
||||
arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc);
|
||||
|
||||
/**
|
||||
* Return average network hashes per second based on the last 'lookup' blocks,
|
||||
* or over the difficulty averaging window if 'lookup' is nonpositive.
|
||||
* If 'height' is nonnegative, compute the estimate at the time when a given block was found.
|
||||
*/
|
||||
int64_t GetNetworkHashPS(int lookup, int height) {
|
||||
CBlockIndex *pb = chainActive.LastTip();
|
||||
|
||||
if (height >= 0 && height < chainActive.Height())
|
||||
pb = chainActive[height];
|
||||
|
||||
if (pb == NULL || !pb->nHeight)
|
||||
return 0;
|
||||
|
||||
// If lookup is nonpositive, then use difficulty averaging window.
|
||||
if (lookup <= 0)
|
||||
lookup = Params().GetConsensus().nPowAveragingWindow;
|
||||
|
||||
// If lookup is larger than chain, then set it to chain length.
|
||||
if (lookup > pb->nHeight)
|
||||
lookup = pb->nHeight;
|
||||
|
||||
CBlockIndex *pb0 = pb;
|
||||
int64_t minTime = pb0->GetBlockTime();
|
||||
int64_t maxTime = minTime;
|
||||
for (int i = 0; i < lookup; i++) {
|
||||
pb0 = pb0->pprev;
|
||||
int64_t time = pb0->GetBlockTime();
|
||||
minTime = std::min(time, minTime);
|
||||
maxTime = std::max(time, maxTime);
|
||||
}
|
||||
|
||||
// In case there's a situation where minTime == maxTime, we don't want a divide by zero exception.
|
||||
if (minTime == maxTime)
|
||||
return 0;
|
||||
|
||||
arith_uint256 workDiff = pb->nChainWork - pb0->nChainWork;
|
||||
int64_t timeDiff = maxTime - minTime;
|
||||
|
||||
return (int64_t)(workDiff.getdouble() / timeDiff);
|
||||
}
|
||||
|
||||
UniValue getlocalsolps(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp)
|
||||
throw runtime_error(
|
||||
"getlocalsolps\n"
|
||||
"\nReturns the average local solutions per second since this node was started.\n"
|
||||
"This is the same information shown on the metrics screen (if enabled).\n"
|
||||
"\nResult:\n"
|
||||
"xxx.xxxxx (numeric) Solutions per second average\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("getlocalsolps", "")
|
||||
+ HelpExampleRpc("getlocalsolps", "")
|
||||
);
|
||||
|
||||
LOCK(cs_main);
|
||||
return GetLocalSolPS();
|
||||
}
|
||||
|
||||
UniValue getnetworksolps(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() > 2)
|
||||
throw runtime_error(
|
||||
"getnetworksolps ( blocks height )\n"
|
||||
"\nReturns the estimated network solutions per second based on the last n blocks.\n"
|
||||
"Pass in [blocks] to override # of blocks, -1 specifies over difficulty averaging window.\n"
|
||||
"Pass in [height] to estimate the network speed at the time when a certain block was found.\n"
|
||||
"\nArguments:\n"
|
||||
"1. blocks (numeric, optional, default=120) The number of blocks, or -1 for blocks over difficulty averaging window.\n"
|
||||
"2. height (numeric, optional, default=-1) To estimate at the time of the given height.\n"
|
||||
"\nResult:\n"
|
||||
"x (numeric) Solutions per second estimated\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("getnetworksolps", "")
|
||||
+ HelpExampleRpc("getnetworksolps", "")
|
||||
);
|
||||
|
||||
LOCK(cs_main);
|
||||
return GetNetworkHashPS(params.size() > 0 ? params[0].get_int() : 120, params.size() > 1 ? params[1].get_int() : -1);
|
||||
}
|
||||
|
||||
UniValue getnetworkhashps(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() > 2)
|
||||
throw runtime_error(
|
||||
"getnetworkhashps ( blocks height )\n"
|
||||
"\nDEPRECATED - left for backwards-compatibility. Use getnetworksolps instead.\n"
|
||||
"\nReturns the estimated network solutions per second based on the last n blocks.\n"
|
||||
"Pass in [blocks] to override # of blocks, -1 specifies over difficulty averaging window.\n"
|
||||
"Pass in [height] to estimate the network speed at the time when a certain block was found.\n"
|
||||
"\nArguments:\n"
|
||||
"1. blocks (numeric, optional, default=120) The number of blocks, or -1 for blocks over difficulty averaging window.\n"
|
||||
"2. height (numeric, optional, default=-1) To estimate at the time of the given height.\n"
|
||||
"\nResult:\n"
|
||||
"x (numeric) Solutions per second estimated\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("getnetworkhashps", "")
|
||||
+ HelpExampleRpc("getnetworkhashps", "")
|
||||
);
|
||||
|
||||
LOCK(cs_main);
|
||||
return GetNetworkHashPS(params.size() > 0 ? params[0].get_int() : 120, params.size() > 1 ? params[1].get_int() : -1);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_MINING
|
||||
UniValue getgenerate(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
throw runtime_error(
|
||||
"getgenerate\n"
|
||||
"\nReturn if the server is set to generate coins or not. The default is false.\n"
|
||||
"It is set with the command line argument -gen (or komodo.conf setting gen)\n"
|
||||
"It can also be set with the setgenerate call.\n"
|
||||
"\nResult\n"
|
||||
"true|false (boolean) If the server is set to generate coins or not\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("getgenerate", "")
|
||||
+ HelpExampleRpc("getgenerate", "")
|
||||
);
|
||||
|
||||
LOCK(cs_main);
|
||||
return GetBoolArg("-gen", false);
|
||||
}
|
||||
|
||||
extern uint8_t NOTARY_PUBKEY33[33];
|
||||
|
||||
//Value generate(const Array& params, bool fHelp)
|
||||
UniValue generate(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() < 1 || params.size() > 1)
|
||||
throw runtime_error(
|
||||
"generate numblocks\n"
|
||||
"\nMine blocks immediately (before the RPC call returns)\n"
|
||||
"\nNote: this function can only be used on the regtest network\n"
|
||||
"\nArguments:\n"
|
||||
"1. numblocks (numeric) How many blocks are generated immediately.\n"
|
||||
"\nResult\n"
|
||||
"[ blockhashes ] (array) hashes of blocks generated\n"
|
||||
"\nExamples:\n"
|
||||
"\nGenerate 11 blocks\n"
|
||||
+ HelpExampleCli("generate", "11")
|
||||
);
|
||||
|
||||
if (GetArg("-mineraddress", "").empty()) {
|
||||
#ifdef ENABLE_WALLET
|
||||
if (!pwalletMain) {
|
||||
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Wallet disabled and -mineraddress not set");
|
||||
}
|
||||
#else
|
||||
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "komodod compiled without wallet and -mineraddress not set");
|
||||
#endif
|
||||
}
|
||||
if (!Params().MineBlocksOnDemand())
|
||||
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "This method can only be used on regtest");
|
||||
|
||||
int nHeightStart = 0;
|
||||
int nHeightEnd = 0;
|
||||
int nHeight = 0;
|
||||
int nGenerate = params[0].get_int();
|
||||
#ifdef ENABLE_WALLET
|
||||
CReserveKey reservekey(pwalletMain);
|
||||
#endif
|
||||
|
||||
{ // Don't keep cs_main locked
|
||||
LOCK(cs_main);
|
||||
nHeightStart = chainActive.Height();
|
||||
nHeight = nHeightStart;
|
||||
nHeightEnd = nHeightStart+nGenerate;
|
||||
}
|
||||
unsigned int nExtraNonce = 0;
|
||||
UniValue blockHashes(UniValue::VARR);
|
||||
unsigned int n = Params().EquihashN();
|
||||
unsigned int k = Params().EquihashK();
|
||||
uint64_t lastTime = 0;
|
||||
while (nHeight < nHeightEnd)
|
||||
{
|
||||
// Validation may fail if block generation is too fast
|
||||
if (GetTime() == lastTime) MilliSleep(1001);
|
||||
lastTime = GetTime();
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
std::unique_ptr<CBlockTemplate> pblocktemplate(CreateNewBlockWithKey(reservekey,nHeight,KOMODO_MAXGPUCOUNT));
|
||||
#else
|
||||
std::unique_ptr<CBlockTemplate> pblocktemplate(CreateNewBlockWithKey());
|
||||
#endif
|
||||
if (!pblocktemplate.get())
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Wallet keypool empty");
|
||||
CBlock *pblock = &pblocktemplate->block;
|
||||
{
|
||||
LOCK(cs_main);
|
||||
IncrementExtraNonce(pblock, chainActive.LastTip(), nExtraNonce);
|
||||
}
|
||||
|
||||
// Hash state
|
||||
crypto_generichash_blake2b_state eh_state;
|
||||
EhInitialiseState(n, k, eh_state);
|
||||
|
||||
// I = the block header minus nonce and solution.
|
||||
CEquihashInput I{*pblock};
|
||||
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ss << I;
|
||||
|
||||
// H(I||...
|
||||
crypto_generichash_blake2b_update(&eh_state, (unsigned char*)&ss[0], ss.size());
|
||||
|
||||
while (true) {
|
||||
// Yes, there is a chance every nonce could fail to satisfy the -regtest
|
||||
// target -- 1 in 2^(2^256). That ain't gonna happen
|
||||
pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1);
|
||||
|
||||
// H(I||V||...
|
||||
crypto_generichash_blake2b_state curr_state;
|
||||
curr_state = eh_state;
|
||||
crypto_generichash_blake2b_update(&curr_state,
|
||||
pblock->nNonce.begin(),
|
||||
pblock->nNonce.size());
|
||||
|
||||
// (x_1, x_2, ...) = A(I, V, n, k)
|
||||
std::function<bool(std::vector<unsigned char>)> validBlock =
|
||||
[&pblock](std::vector<unsigned char> soln)
|
||||
{
|
||||
LOCK(cs_main);
|
||||
pblock->nSolution = soln;
|
||||
solutionTargetChecks.increment();
|
||||
return CheckProofOfWork(chainActive.Height(),NOTARY_PUBKEY33,pblock->GetHash(), pblock->nBits, Params().GetConsensus(),pblock->nTime);
|
||||
};
|
||||
bool found = EhBasicSolveUncancellable(n, k, curr_state, validBlock);
|
||||
ehSolverRuns.increment();
|
||||
if (found) {
|
||||
goto endloop;
|
||||
}
|
||||
}
|
||||
endloop:
|
||||
CValidationState state;
|
||||
if (!ProcessNewBlock(1,chainActive.LastTip()->nHeight+1,state, NULL, pblock, true, NULL))
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted");
|
||||
++nHeight;
|
||||
blockHashes.push_back(pblock->GetHash().GetHex());
|
||||
}
|
||||
return blockHashes;
|
||||
}
|
||||
|
||||
|
||||
UniValue setgenerate(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() < 1 || params.size() > 2)
|
||||
throw runtime_error(
|
||||
"setgenerate generate ( genproclimit )\n"
|
||||
"\nSet 'generate' true or false to turn generation on or off.\n"
|
||||
"Generation is limited to 'genproclimit' processors, -1 is unlimited.\n"
|
||||
"See the getgenerate call for the current setting.\n"
|
||||
"\nArguments:\n"
|
||||
"1. generate (boolean, required) Set to true to turn on generation, off to turn off.\n"
|
||||
"2. genproclimit (numeric, optional) Set the processor limit for when generation is on. Can be -1 for unlimited.\n"
|
||||
"\nExamples:\n"
|
||||
"\nSet the generation on with a limit of one processor\n"
|
||||
+ HelpExampleCli("setgenerate", "true 1") +
|
||||
"\nCheck the setting\n"
|
||||
+ HelpExampleCli("getgenerate", "") +
|
||||
"\nTurn off generation\n"
|
||||
+ HelpExampleCli("setgenerate", "false") +
|
||||
"\nUsing json rpc\n"
|
||||
+ HelpExampleRpc("setgenerate", "true, 1")
|
||||
);
|
||||
|
||||
if (GetArg("-mineraddress", "").empty()) {
|
||||
#ifdef ENABLE_WALLET
|
||||
if (!pwalletMain) {
|
||||
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Wallet disabled and -mineraddress not set");
|
||||
}
|
||||
#else
|
||||
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "komodod compiled without wallet and -mineraddress not set");
|
||||
#endif
|
||||
}
|
||||
if (Params().MineBlocksOnDemand())
|
||||
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Use the generate method instead of setgenerate on this network");
|
||||
|
||||
bool fGenerate = true;
|
||||
if (params.size() > 0)
|
||||
fGenerate = params[0].get_bool();
|
||||
|
||||
int nGenProcLimit = -1;
|
||||
if (params.size() > 1)
|
||||
{
|
||||
nGenProcLimit = params[1].get_int();
|
||||
//if (nGenProcLimit == 0)
|
||||
// fGenerate = false;
|
||||
}
|
||||
|
||||
mapArgs["-gen"] = (fGenerate ? "1" : "0");
|
||||
mapArgs ["-genproclimit"] = itostr(nGenProcLimit);
|
||||
if ( fGenerate == 0 )
|
||||
KOMODO_MININGTHREADS = -1;
|
||||
else KOMODO_MININGTHREADS = (int32_t)nGenProcLimit;
|
||||
#ifdef ENABLE_WALLET
|
||||
GenerateBitcoins(fGenerate, pwalletMain, nGenProcLimit);
|
||||
#else
|
||||
GenerateBitcoins(fGenerate, nGenProcLimit);
|
||||
#endif
|
||||
|
||||
return NullUniValue;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
UniValue getmininginfo(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
throw runtime_error(
|
||||
"getmininginfo\n"
|
||||
"\nReturns a json object containing mining-related information."
|
||||
"\nResult:\n"
|
||||
"{\n"
|
||||
" \"blocks\": nnn, (numeric) The current block\n"
|
||||
" \"currentblocksize\": nnn, (numeric) The last block size\n"
|
||||
" \"currentblocktx\": nnn, (numeric) The last block transaction\n"
|
||||
" \"difficulty\": xxx.xxxxx (numeric) The current difficulty\n"
|
||||
" \"errors\": \"...\" (string) Current errors\n"
|
||||
" \"generate\": true|false (boolean) If the generation is on or off (see getgenerate or setgenerate calls)\n"
|
||||
" \"genproclimit\": n (numeric) The processor limit for generation. -1 if no generation. (see getgenerate or setgenerate calls)\n"
|
||||
" \"localsolps\": xxx.xxxxx (numeric) The average local solution rate in Sol/s since this node was started\n"
|
||||
" \"networksolps\": x (numeric) The estimated network solution rate in Sol/s\n"
|
||||
" \"pooledtx\": n (numeric) The size of the mem pool\n"
|
||||
" \"testnet\": true|false (boolean) If using testnet or not\n"
|
||||
" \"chain\": \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest)\n"
|
||||
"}\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("getmininginfo", "")
|
||||
+ HelpExampleRpc("getmininginfo", "")
|
||||
);
|
||||
|
||||
|
||||
LOCK(cs_main);
|
||||
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.push_back(Pair("blocks", (int)chainActive.Height()));
|
||||
obj.push_back(Pair("currentblocksize", (uint64_t)nLastBlockSize));
|
||||
obj.push_back(Pair("currentblocktx", (uint64_t)nLastBlockTx));
|
||||
obj.push_back(Pair("difficulty", (double)GetNetworkDifficulty()));
|
||||
obj.push_back(Pair("errors", GetWarnings("statusbar")));
|
||||
obj.push_back(Pair("genproclimit", (int)GetArg("-genproclimit", -1)));
|
||||
obj.push_back(Pair("localsolps" , getlocalsolps(params, false)));
|
||||
obj.push_back(Pair("networksolps", getnetworksolps(params, false)));
|
||||
obj.push_back(Pair("networkhashps", getnetworksolps(params, false)));
|
||||
obj.push_back(Pair("pooledtx", (uint64_t)mempool.size()));
|
||||
obj.push_back(Pair("testnet", Params().TestnetToBeDeprecatedFieldRPC()));
|
||||
obj.push_back(Pair("chain", Params().NetworkIDString()));
|
||||
#ifdef ENABLE_MINING
|
||||
obj.push_back(Pair("generate", getgenerate(params, false)));
|
||||
obj.push_back(Pair("numthreads", (int64_t)KOMODO_MININGTHREADS));
|
||||
#endif
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
// NOTE: Unlike wallet RPC (which use BTC values), mining RPCs follow GBT (BIP 22) in using satoshi amounts
|
||||
UniValue prioritisetransaction(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 3)
|
||||
throw runtime_error(
|
||||
"prioritisetransaction <txid> <priority delta> <fee delta>\n"
|
||||
"Accepts the transaction into mined blocks at a higher (or lower) priority\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"txid\" (string, required) The transaction id.\n"
|
||||
"2. priority delta (numeric, required) The priority to add or subtract.\n"
|
||||
" The transaction selection algorithm considers the tx as it would have a higher priority.\n"
|
||||
" (priority of a transaction is calculated: coinage * value_in_satoshis / txsize) \n"
|
||||
"3. fee delta (numeric, required) The fee value (in satoshis) to add (or subtract, if negative).\n"
|
||||
" The fee is not actually paid, only the algorithm for selecting transactions into a block\n"
|
||||
" considers the transaction as it would have paid a higher (or lower) fee.\n"
|
||||
"\nResult\n"
|
||||
"true (boolean) Returns true\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("prioritisetransaction", "\"txid\" 0.0 10000")
|
||||
+ HelpExampleRpc("prioritisetransaction", "\"txid\", 0.0, 10000")
|
||||
);
|
||||
|
||||
LOCK(cs_main);
|
||||
|
||||
uint256 hash = ParseHashStr(params[0].get_str(), "txid");
|
||||
CAmount nAmount = params[2].get_int64();
|
||||
|
||||
mempool.PrioritiseTransaction(hash, params[0].get_str(), params[1].get_real(), nAmount);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// NOTE: Assumes a conclusive result; if result is inconclusive, it must be handled by caller
|
||||
static UniValue BIP22ValidationResult(const CValidationState& state)
|
||||
{
|
||||
if (state.IsValid())
|
||||
return NullUniValue;
|
||||
|
||||
std::string strRejectReason = state.GetRejectReason();
|
||||
if (state.IsError())
|
||||
throw JSONRPCError(RPC_VERIFY_ERROR, strRejectReason);
|
||||
if (state.IsInvalid())
|
||||
{
|
||||
if (strRejectReason.empty())
|
||||
return "rejected";
|
||||
return strRejectReason;
|
||||
}
|
||||
// Should be impossible
|
||||
return "valid?";
|
||||
}
|
||||
|
||||
UniValue getblocktemplate(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() > 1)
|
||||
throw runtime_error(
|
||||
"getblocktemplate ( \"jsonrequestobject\" )\n"
|
||||
"\nIf the request parameters include a 'mode' key, that is used to explicitly select between the default 'template' request or a 'proposal'.\n"
|
||||
"It returns data needed to construct a block to work on.\n"
|
||||
"See https://en.bitcoin.it/wiki/BIP_0022 for full specification.\n"
|
||||
|
||||
"\nArguments:\n"
|
||||
"1. \"jsonrequestobject\" (string, optional) A json object in the following spec\n"
|
||||
" {\n"
|
||||
" \"mode\":\"template\" (string, optional) This must be set to \"template\" or omitted\n"
|
||||
" \"capabilities\":[ (array, optional) A list of strings\n"
|
||||
" \"support\" (string) client side supported feature, 'longpoll', 'coinbasetxn', 'coinbasevalue', 'proposal', 'serverlist', 'workid'\n"
|
||||
" ,...\n"
|
||||
" ]\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
|
||||
"\nResult:\n"
|
||||
"{\n"
|
||||
" \"version\" : n, (numeric) The block version\n"
|
||||
" \"previousblockhash\" : \"xxxx\", (string) The hash of current highest block\n"
|
||||
" \"transactions\" : [ (array) contents of non-coinbase transactions that should be included in the next block\n"
|
||||
" {\n"
|
||||
" \"data\" : \"xxxx\", (string) transaction data encoded in hexadecimal (byte-for-byte)\n"
|
||||
" \"hash\" : \"xxxx\", (string) hash/id encoded in little-endian hexadecimal\n"
|
||||
" \"depends\" : [ (array) array of numbers \n"
|
||||
" n (numeric) transactions before this one (by 1-based index in 'transactions' list) that must be present in the final block if this one is\n"
|
||||
" ,...\n"
|
||||
" ],\n"
|
||||
" \"fee\": n, (numeric) difference in value between transaction inputs and outputs (in Satoshis); for coinbase transactions, this is a negative Number of the total collected block fees (ie, not including the block subsidy); if key is not present, fee is unknown and clients MUST NOT assume there isn't one\n"
|
||||
" \"sigops\" : n, (numeric) total number of SigOps, as counted for purposes of block limits; if key is not present, sigop count is unknown and clients MUST NOT assume there aren't any\n"
|
||||
" \"required\" : true|false (boolean) if provided and true, this transaction must be in the final block\n"
|
||||
" }\n"
|
||||
" ,...\n"
|
||||
" ],\n"
|
||||
// " \"coinbaseaux\" : { (json object) data that should be included in the coinbase's scriptSig content\n"
|
||||
// " \"flags\" : \"flags\" (string) \n"
|
||||
// " },\n"
|
||||
// " \"coinbasevalue\" : n, (numeric) maximum allowable input to coinbase transaction, including the generation award and transaction fees (in Satoshis)\n"
|
||||
" \"coinbasetxn\" : { ... }, (json object) information for coinbase transaction\n"
|
||||
" \"target\" : \"xxxx\", (string) The hash target\n"
|
||||
" \"mintime\" : xxx, (numeric) The minimum timestamp appropriate for next block time in seconds since epoch (Jan 1 1970 GMT)\n"
|
||||
" \"mutable\" : [ (array of string) list of ways the block template may be changed \n"
|
||||
" \"value\" (string) A way the block template may be changed, e.g. 'time', 'transactions', 'prevblock'\n"
|
||||
" ,...\n"
|
||||
" ],\n"
|
||||
" \"noncerange\" : \"00000000ffffffff\", (string) A range of valid nonces\n"
|
||||
" \"sigoplimit\" : n, (numeric) limit of sigops in blocks\n"
|
||||
" \"sizelimit\" : n, (numeric) limit of block size\n"
|
||||
" \"curtime\" : ttt, (numeric) current timestamp in seconds since epoch (Jan 1 1970 GMT)\n"
|
||||
" \"bits\" : \"xxx\", (string) compressed target of next block\n"
|
||||
" \"height\" : n (numeric) The height of the next block\n"
|
||||
"}\n"
|
||||
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("getblocktemplate", "")
|
||||
+ HelpExampleRpc("getblocktemplate", "")
|
||||
);
|
||||
|
||||
LOCK(cs_main);
|
||||
|
||||
// Wallet or miner address is required because we support coinbasetxn
|
||||
if (GetArg("-mineraddress", "").empty()) {
|
||||
#ifdef ENABLE_WALLET
|
||||
if (!pwalletMain) {
|
||||
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Wallet disabled and -mineraddress not set");
|
||||
}
|
||||
#else
|
||||
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "komodod compiled without wallet and -mineraddress not set");
|
||||
#endif
|
||||
}
|
||||
|
||||
UniValue lpval = NullUniValue;
|
||||
// TODO: Re-enable coinbasevalue once a specification has been written
|
||||
bool coinbasetxn = true;
|
||||
std::string strMode;
|
||||
if (params.size() > 0)
|
||||
{
|
||||
const UniValue& oparam = params[0].get_obj();
|
||||
const UniValue& modeval = find_value(oparam, "mode");
|
||||
if (modeval.isStr())
|
||||
strMode = modeval.get_str();
|
||||
else if (modeval.isNull())
|
||||
{
|
||||
strMode = "template";
|
||||
}
|
||||
else
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
|
||||
lpval = find_value(oparam, "longpollid");
|
||||
|
||||
if (strMode == "disablecb")
|
||||
coinbasetxn = false;
|
||||
|
||||
if (strMode == "proposal")
|
||||
{
|
||||
const UniValue& dataval = find_value(oparam, "data");
|
||||
if (!dataval.isStr())
|
||||
throw JSONRPCError(RPC_TYPE_ERROR, "Missing data String key for proposal");
|
||||
|
||||
CBlock block;
|
||||
if (!DecodeHexBlk(block, dataval.get_str()))
|
||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
|
||||
|
||||
uint256 hash = block.GetHash();
|
||||
BlockMap::iterator mi = mapBlockIndex.find(hash);
|
||||
if (mi != mapBlockIndex.end()) {
|
||||
CBlockIndex *pindex = mi->second;
|
||||
if (pindex->IsValid(BLOCK_VALID_SCRIPTS))
|
||||
return "duplicate";
|
||||
if (pindex->nStatus & BLOCK_FAILED_MASK)
|
||||
return "duplicate-invalid";
|
||||
return "duplicate-inconclusive";
|
||||
}
|
||||
|
||||
CBlockIndex* const pindexPrev = chainActive.LastTip();
|
||||
// TestBlockValidity only supports blocks built on the current Tip
|
||||
if (block.hashPrevBlock != pindexPrev->GetBlockHash())
|
||||
return "inconclusive-not-best-prevblk";
|
||||
CValidationState state;
|
||||
TestBlockValidity(state, block, pindexPrev, false, true);
|
||||
return BIP22ValidationResult(state);
|
||||
}
|
||||
}
|
||||
|
||||
if (vNodes.empty())
|
||||
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Komodo is not connected!");
|
||||
|
||||
//if (IsInitialBlockDownload())
|
||||
// throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Zcash is downloading blocks...");
|
||||
|
||||
static unsigned int nTransactionsUpdatedLast;
|
||||
|
||||
if (!lpval.isNull())
|
||||
{
|
||||
// Wait to respond until either the best block changes, OR a minute has passed and there are more transactions
|
||||
uint256 hashWatchedChain;
|
||||
boost::system_time checktxtime;
|
||||
unsigned int nTransactionsUpdatedLastLP;
|
||||
|
||||
if (lpval.isStr())
|
||||
{
|
||||
// Format: <hashBestChain><nTransactionsUpdatedLast>
|
||||
std::string lpstr = lpval.get_str();
|
||||
|
||||
hashWatchedChain.SetHex(lpstr.substr(0, 64));
|
||||
nTransactionsUpdatedLastLP = atoi64(lpstr.substr(64));
|
||||
}
|
||||
else
|
||||
{
|
||||
// NOTE: Spec does not specify behaviour for non-string longpollid, but this makes testing easier
|
||||
hashWatchedChain = chainActive.LastTip()->GetBlockHash();
|
||||
nTransactionsUpdatedLastLP = nTransactionsUpdatedLast;
|
||||
}
|
||||
|
||||
// Release the wallet and main lock while waiting
|
||||
LEAVE_CRITICAL_SECTION(cs_main);
|
||||
{
|
||||
checktxtime = boost::get_system_time() + boost::posix_time::minutes(1);
|
||||
|
||||
boost::unique_lock<boost::mutex> lock(csBestBlock);
|
||||
while (chainActive.LastTip()->GetBlockHash() == hashWatchedChain && IsRPCRunning())
|
||||
{
|
||||
if (!cvBlockChange.timed_wait(lock, checktxtime))
|
||||
{
|
||||
// Timeout: Check transactions for update
|
||||
if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLastLP)
|
||||
break;
|
||||
checktxtime += boost::posix_time::seconds(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
ENTER_CRITICAL_SECTION(cs_main);
|
||||
|
||||
if (!IsRPCRunning())
|
||||
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Shutting down");
|
||||
// TODO: Maybe recheck connections/IBD and (if something wrong) send an expires-immediately template to stop miners?
|
||||
}
|
||||
|
||||
// Update block
|
||||
static CBlockIndex* pindexPrev;
|
||||
static int64_t nStart;
|
||||
static CBlockTemplate* pblocktemplate;
|
||||
if (pindexPrev != chainActive.LastTip() ||
|
||||
(mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 5))
|
||||
{
|
||||
// Clear pindexPrev so future calls make a new block, despite any failures from here on
|
||||
pindexPrev = NULL;
|
||||
|
||||
// Store the pindexBest used before CreateNewBlockWithKey, to avoid races
|
||||
nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
|
||||
CBlockIndex* pindexPrevNew = chainActive.LastTip();
|
||||
nStart = GetTime();
|
||||
|
||||
// Create new block
|
||||
if(pblocktemplate)
|
||||
{
|
||||
delete pblocktemplate;
|
||||
pblocktemplate = NULL;
|
||||
}
|
||||
#ifdef ENABLE_WALLET
|
||||
CReserveKey reservekey(pwalletMain);
|
||||
pblocktemplate = CreateNewBlockWithKey(reservekey,chainActive.LastTip()->nHeight+1,KOMODO_MAXGPUCOUNT);
|
||||
#else
|
||||
pblocktemplate = CreateNewBlockWithKey();
|
||||
#endif
|
||||
if (!pblocktemplate)
|
||||
throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory or no available utxo for staking");
|
||||
|
||||
// Need to update only after we know CreateNewBlockWithKey succeeded
|
||||
pindexPrev = pindexPrevNew;
|
||||
}
|
||||
CBlock* pblock = &pblocktemplate->block; // pointer for convenience
|
||||
|
||||
// Update nTime
|
||||
UpdateTime(pblock, Params().GetConsensus(), pindexPrev);
|
||||
pblock->nNonce = uint256();
|
||||
|
||||
UniValue aCaps(UniValue::VARR); aCaps.push_back("proposal");
|
||||
|
||||
UniValue txCoinbase = NullUniValue;
|
||||
UniValue transactions(UniValue::VARR);
|
||||
map<uint256, int64_t> setTxIndex;
|
||||
int i = 0;
|
||||
BOOST_FOREACH (const CTransaction& tx, pblock->vtx) {
|
||||
uint256 txHash = tx.GetHash();
|
||||
setTxIndex[txHash] = i++;
|
||||
|
||||
//if (tx.IsCoinBase() && !coinbasetxn)
|
||||
// continue;
|
||||
|
||||
UniValue entry(UniValue::VOBJ);
|
||||
|
||||
entry.push_back(Pair("data", EncodeHexTx(tx)));
|
||||
|
||||
entry.push_back(Pair("hash", txHash.GetHex()));
|
||||
|
||||
UniValue deps(UniValue::VARR);
|
||||
BOOST_FOREACH (const CTxIn &in, tx.vin)
|
||||
{
|
||||
if (setTxIndex.count(in.prevout.hash))
|
||||
deps.push_back(setTxIndex[in.prevout.hash]);
|
||||
}
|
||||
entry.push_back(Pair("depends", deps));
|
||||
|
||||
int index_in_template = i - 1;
|
||||
entry.push_back(Pair("fee", pblocktemplate->vTxFees[index_in_template]));
|
||||
entry.push_back(Pair("sigops", pblocktemplate->vTxSigOps[index_in_template]));
|
||||
|
||||
if (tx.IsCoinBase() && coinbasetxn == true ) {
|
||||
// Show founders' reward if it is required
|
||||
//if (pblock->vtx[0].vout.size() > 1) {
|
||||
// Correct this if GetBlockTemplate changes the order
|
||||
// entry.push_back(Pair("foundersreward", (int64_t)tx.vout[1].nValue));
|
||||
//}
|
||||
CAmount nReward = GetBlockSubsidy(chainActive.LastTip()->nHeight+1, Params().GetConsensus());
|
||||
entry.push_back(Pair("coinbasevalue", nReward));
|
||||
entry.push_back(Pair("required", true));
|
||||
txCoinbase = entry;
|
||||
} else
|
||||
transactions.push_back(entry);
|
||||
}
|
||||
|
||||
UniValue aux(UniValue::VOBJ);
|
||||
aux.push_back(Pair("flags", HexStr(COINBASE_FLAGS.begin(), COINBASE_FLAGS.end())));
|
||||
|
||||
arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits);
|
||||
|
||||
static UniValue aMutable(UniValue::VARR);
|
||||
if (aMutable.empty())
|
||||
{
|
||||
aMutable.push_back("time");
|
||||
aMutable.push_back("transactions");
|
||||
aMutable.push_back("prevblock");
|
||||
}
|
||||
|
||||
UniValue result(UniValue::VOBJ);
|
||||
result.push_back(Pair("capabilities", aCaps));
|
||||
result.push_back(Pair("version", pblock->nVersion));
|
||||
result.push_back(Pair("previousblockhash", pblock->hashPrevBlock.GetHex()));
|
||||
result.push_back(Pair("transactions", transactions));
|
||||
if (coinbasetxn) {
|
||||
assert(txCoinbase.isObject());
|
||||
result.push_back(Pair("coinbasetxn", txCoinbase));
|
||||
} // else {
|
||||
// result.push_back(Pair("coinbaseaux", aux));
|
||||
// result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0].vout[0].nValue));
|
||||
//}
|
||||
result.push_back(Pair("longpollid", chainActive.LastTip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast)));
|
||||
if ( ASSETCHAINS_STAKED != 0 )
|
||||
{
|
||||
arith_uint256 POWtarget; int32_t PoSperc;
|
||||
POWtarget = komodo_PoWtarget(&PoSperc,hashTarget,(int32_t)(pindexPrev->nHeight+1),ASSETCHAINS_STAKED);
|
||||
result.push_back(Pair("target", POWtarget.GetHex()));
|
||||
result.push_back(Pair("PoSperc", (int64_t)PoSperc));
|
||||
result.push_back(Pair("ac_staked", (int64_t)ASSETCHAINS_STAKED));
|
||||
result.push_back(Pair("origtarget", hashTarget.GetHex()));
|
||||
} else result.push_back(Pair("target", hashTarget.GetHex()));
|
||||
result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1));
|
||||
result.push_back(Pair("mutable", aMutable));
|
||||
result.push_back(Pair("noncerange", "00000000ffffffff"));
|
||||
result.push_back(Pair("sigoplimit", (int64_t)MAX_BLOCK_SIGOPS));
|
||||
result.push_back(Pair("sizelimit", (int64_t)MAX_BLOCK_SIZE));
|
||||
result.push_back(Pair("curtime", pblock->GetBlockTime()));
|
||||
result.push_back(Pair("bits", strprintf("%08x", pblock->nBits)));
|
||||
result.push_back(Pair("height", (int64_t)(pindexPrev->nHeight+1)));
|
||||
|
||||
//fprintf(stderr,"return complete template\n");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
class submitblock_StateCatcher : public CValidationInterface
|
||||
{
|
||||
public:
|
||||
uint256 hash;
|
||||
bool found;
|
||||
CValidationState state;
|
||||
|
||||
submitblock_StateCatcher(const uint256 &hashIn) : hash(hashIn), found(false), state() {};
|
||||
|
||||
protected:
|
||||
virtual void BlockChecked(const CBlock& block, const CValidationState& stateIn) {
|
||||
if (block.GetHash() != hash)
|
||||
return;
|
||||
found = true;
|
||||
state = stateIn;
|
||||
};
|
||||
};
|
||||
|
||||
UniValue submitblock(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() < 1 || params.size() > 2)
|
||||
throw runtime_error(
|
||||
"submitblock \"hexdata\" ( \"jsonparametersobject\" )\n"
|
||||
"\nAttempts to submit new block to network.\n"
|
||||
"The 'jsonparametersobject' parameter is currently ignored.\n"
|
||||
"See https://en.bitcoin.it/wiki/BIP_0022 for full specification.\n"
|
||||
|
||||
"\nArguments\n"
|
||||
"1. \"hexdata\" (string, required) the hex-encoded block data to submit\n"
|
||||
"2. \"jsonparametersobject\" (string, optional) object of optional parameters\n"
|
||||
" {\n"
|
||||
" \"workid\" : \"id\" (string, optional) if the server provided a workid, it MUST be included with submissions\n"
|
||||
" }\n"
|
||||
"\nResult:\n"
|
||||
"\"duplicate\" - node already has valid copy of block\n"
|
||||
"\"duplicate-invalid\" - node already has block, but it is invalid\n"
|
||||
"\"duplicate-inconclusive\" - node already has block but has not validated it\n"
|
||||
"\"inconclusive\" - node has not validated the block, it may not be on the node's current best chain\n"
|
||||
"\"rejected\" - block was rejected as invalid\n"
|
||||
"For more information on submitblock parameters and results, see: https://github.com/bitcoin/bips/blob/master/bip-0022.mediawiki#block-submission\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("submitblock", "\"mydata\"")
|
||||
+ HelpExampleRpc("submitblock", "\"mydata\"")
|
||||
);
|
||||
|
||||
CBlock block;
|
||||
if (!DecodeHexBlk(block, params[0].get_str()))
|
||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
|
||||
|
||||
uint256 hash = block.GetHash();
|
||||
bool fBlockPresent = false;
|
||||
{
|
||||
LOCK(cs_main);
|
||||
BlockMap::iterator mi = mapBlockIndex.find(hash);
|
||||
if (mi != mapBlockIndex.end()) {
|
||||
CBlockIndex *pindex = mi->second;
|
||||
if (pindex->IsValid(BLOCK_VALID_SCRIPTS))
|
||||
return "duplicate";
|
||||
if (pindex->nStatus & BLOCK_FAILED_MASK)
|
||||
return "duplicate-invalid";
|
||||
// Otherwise, we might only have the header - process the block before returning
|
||||
fBlockPresent = true;
|
||||
}
|
||||
}
|
||||
|
||||
CValidationState state;
|
||||
submitblock_StateCatcher sc(block.GetHash());
|
||||
RegisterValidationInterface(&sc);
|
||||
bool fAccepted = ProcessNewBlock(1,chainActive.LastTip()->nHeight+1,state, NULL, &block, true, NULL);
|
||||
UnregisterValidationInterface(&sc);
|
||||
if (fBlockPresent)
|
||||
{
|
||||
if (fAccepted && !sc.found)
|
||||
return "duplicate-inconclusive";
|
||||
return "duplicate";
|
||||
}
|
||||
if (fAccepted)
|
||||
{
|
||||
if (!sc.found)
|
||||
return "inconclusive";
|
||||
state = sc.state;
|
||||
}
|
||||
return BIP22ValidationResult(state);
|
||||
}
|
||||
|
||||
UniValue estimatefee(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 1)
|
||||
throw runtime_error(
|
||||
"estimatefee nblocks\n"
|
||||
"\nEstimates the approximate fee per kilobyte\n"
|
||||
"needed for a transaction to begin confirmation\n"
|
||||
"within nblocks blocks.\n"
|
||||
"\nArguments:\n"
|
||||
"1. nblocks (numeric)\n"
|
||||
"\nResult:\n"
|
||||
"n : (numeric) estimated fee-per-kilobyte\n"
|
||||
"\n"
|
||||
"-1.0 is returned if not enough transactions and\n"
|
||||
"blocks have been observed to make an estimate.\n"
|
||||
"\nExample:\n"
|
||||
+ HelpExampleCli("estimatefee", "6")
|
||||
);
|
||||
|
||||
RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM));
|
||||
|
||||
int nBlocks = params[0].get_int();
|
||||
if (nBlocks < 1)
|
||||
nBlocks = 1;
|
||||
|
||||
CFeeRate feeRate = mempool.estimateFee(nBlocks);
|
||||
if (feeRate == CFeeRate(0))
|
||||
return -1.0;
|
||||
|
||||
return ValueFromAmount(feeRate.GetFeePerK());
|
||||
}
|
||||
|
||||
UniValue estimatepriority(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 1)
|
||||
throw runtime_error(
|
||||
"estimatepriority nblocks\n"
|
||||
"\nEstimates the approximate priority\n"
|
||||
"a zero-fee transaction needs to begin confirmation\n"
|
||||
"within nblocks blocks.\n"
|
||||
"\nArguments:\n"
|
||||
"1. nblocks (numeric)\n"
|
||||
"\nResult:\n"
|
||||
"n : (numeric) estimated priority\n"
|
||||
"\n"
|
||||
"-1.0 is returned if not enough transactions and\n"
|
||||
"blocks have been observed to make an estimate.\n"
|
||||
"\nExample:\n"
|
||||
+ HelpExampleCli("estimatepriority", "6")
|
||||
);
|
||||
|
||||
RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM));
|
||||
|
||||
int nBlocks = params[0].get_int();
|
||||
if (nBlocks < 1)
|
||||
nBlocks = 1;
|
||||
|
||||
return mempool.estimatePriority(nBlocks);
|
||||
}
|
||||
|
||||
UniValue getblocksubsidy(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() > 1)
|
||||
throw runtime_error(
|
||||
"getblocksubsidy height\n"
|
||||
"\nReturns block subsidy reward, taking into account the mining slow start and the founders reward, of block at index provided.\n"
|
||||
"\nArguments:\n"
|
||||
"1. height (numeric, optional) The block height. If not provided, defaults to the current height of the chain.\n"
|
||||
"\nResult:\n"
|
||||
"{\n"
|
||||
" \"miner\" : x.xxx (numeric) The mining reward amount in KMD.\n"
|
||||
"}\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("getblocksubsidy", "1000")
|
||||
+ HelpExampleRpc("getblocksubsidy", "1000")
|
||||
);
|
||||
|
||||
LOCK(cs_main);
|
||||
int nHeight = (params.size()==1) ? params[0].get_int() : chainActive.Height();
|
||||
if (nHeight < 0)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range");
|
||||
|
||||
CAmount nReward = GetBlockSubsidy(nHeight, Params().GetConsensus());
|
||||
UniValue result(UniValue::VOBJ);
|
||||
result.push_back(Pair("miner", ValueFromAmount(nReward)));
|
||||
//result.push_back(Pair("founders", ValueFromAmount(nFoundersReward)));
|
||||
return result;
|
||||
}
|
||||
1232
src/rpcmisc.cpp
1232
src/rpcmisc.cpp
File diff suppressed because it is too large
Load Diff
651
src/rpcnet.cpp
651
src/rpcnet.cpp
@@ -1,651 +0,0 @@
|
||||
// Copyright (c) 2009-2014 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "rpcserver.h"
|
||||
|
||||
#include "clientversion.h"
|
||||
#include "main.h"
|
||||
#include "net.h"
|
||||
#include "netbase.h"
|
||||
#include "protocol.h"
|
||||
#include "sync.h"
|
||||
#include "timedata.h"
|
||||
#include "util.h"
|
||||
#include "version.h"
|
||||
#include "deprecation.h"
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#include <univalue.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
UniValue getconnectioncount(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
throw runtime_error(
|
||||
"getconnectioncount\n"
|
||||
"\nReturns the number of connections to other nodes.\n"
|
||||
"\nbResult:\n"
|
||||
"n (numeric) The connection count\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("getconnectioncount", "")
|
||||
+ HelpExampleRpc("getconnectioncount", "")
|
||||
);
|
||||
|
||||
LOCK2(cs_main, cs_vNodes);
|
||||
|
||||
return (int)vNodes.size();
|
||||
}
|
||||
|
||||
UniValue ping(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
throw runtime_error(
|
||||
"ping\n"
|
||||
"\nRequests that a ping be sent to all other nodes, to measure ping time.\n"
|
||||
"Results provided in getpeerinfo, pingtime and pingwait fields are decimal seconds.\n"
|
||||
"Ping command is handled in queue with all other commands, so it measures processing backlog, not just network ping.\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("ping", "")
|
||||
+ HelpExampleRpc("ping", "")
|
||||
);
|
||||
|
||||
// Request that each node send a ping during next message processing pass
|
||||
LOCK2(cs_main, cs_vNodes);
|
||||
|
||||
BOOST_FOREACH(CNode* pNode, vNodes) {
|
||||
pNode->fPingQueued = true;
|
||||
}
|
||||
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
static void CopyNodeStats(std::vector<CNodeStats>& vstats)
|
||||
{
|
||||
vstats.clear();
|
||||
|
||||
LOCK(cs_vNodes);
|
||||
vstats.reserve(vNodes.size());
|
||||
BOOST_FOREACH(CNode* pnode, vNodes) {
|
||||
CNodeStats stats;
|
||||
pnode->copyStats(stats);
|
||||
vstats.push_back(stats);
|
||||
}
|
||||
}
|
||||
|
||||
UniValue getpeerinfo(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
throw runtime_error(
|
||||
"getpeerinfo\n"
|
||||
"\nReturns data about each connected network node as a json array of objects.\n"
|
||||
"\nbResult:\n"
|
||||
"[\n"
|
||||
" {\n"
|
||||
" \"id\": n, (numeric) Peer index\n"
|
||||
" \"addr\":\"host:port\", (string) The ip address and port of the peer\n"
|
||||
" \"addrlocal\":\"ip:port\", (string) local address\n"
|
||||
" \"services\":\"xxxxxxxxxxxxxxxx\", (string) The services offered\n"
|
||||
" \"lastsend\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last send\n"
|
||||
" \"lastrecv\": ttt, (numeric) The time in seconds since epoch (Jan 1 1970 GMT) of the last receive\n"
|
||||
" \"bytessent\": n, (numeric) The total bytes sent\n"
|
||||
" \"bytesrecv\": n, (numeric) The total bytes received\n"
|
||||
" \"conntime\": ttt, (numeric) The connection time in seconds since epoch (Jan 1 1970 GMT)\n"
|
||||
" \"timeoffset\": ttt, (numeric) The time offset in seconds\n"
|
||||
" \"pingtime\": n, (numeric) ping time\n"
|
||||
" \"pingwait\": n, (numeric) ping wait\n"
|
||||
" \"version\": v, (numeric) The peer version, such as 170002\n"
|
||||
" \"subver\": \"/MagicBean:x.y.z[-v]/\", (string) The string version\n"
|
||||
" \"inbound\": true|false, (boolean) Inbound (true) or Outbound (false)\n"
|
||||
" \"startingheight\": n, (numeric) The starting height (block) of the peer\n"
|
||||
" \"banscore\": n, (numeric) The ban score\n"
|
||||
" \"synced_headers\": n, (numeric) The last header we have in common with this peer\n"
|
||||
" \"synced_blocks\": n, (numeric) The last block we have in common with this peer\n"
|
||||
" \"inflight\": [\n"
|
||||
" n, (numeric) The heights of blocks we're currently asking from this peer\n"
|
||||
" ...\n"
|
||||
" ]\n"
|
||||
" }\n"
|
||||
" ,...\n"
|
||||
"]\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("getpeerinfo", "")
|
||||
+ HelpExampleRpc("getpeerinfo", "")
|
||||
);
|
||||
|
||||
LOCK(cs_main);
|
||||
|
||||
vector<CNodeStats> vstats;
|
||||
CopyNodeStats(vstats);
|
||||
|
||||
UniValue ret(UniValue::VARR);
|
||||
|
||||
BOOST_FOREACH(const CNodeStats& stats, vstats) {
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
CNodeStateStats statestats;
|
||||
bool fStateStats = GetNodeStateStats(stats.nodeid, statestats);
|
||||
obj.push_back(Pair("id", stats.nodeid));
|
||||
obj.push_back(Pair("addr", stats.addrName));
|
||||
if (!(stats.addrLocal.empty()))
|
||||
obj.push_back(Pair("addrlocal", stats.addrLocal));
|
||||
obj.push_back(Pair("services", strprintf("%016x", stats.nServices)));
|
||||
obj.push_back(Pair("lastsend", stats.nLastSend));
|
||||
obj.push_back(Pair("lastrecv", stats.nLastRecv));
|
||||
obj.push_back(Pair("bytessent", stats.nSendBytes));
|
||||
obj.push_back(Pair("bytesrecv", stats.nRecvBytes));
|
||||
obj.push_back(Pair("conntime", stats.nTimeConnected));
|
||||
obj.push_back(Pair("timeoffset", stats.nTimeOffset));
|
||||
obj.push_back(Pair("pingtime", stats.dPingTime));
|
||||
if (stats.dPingWait > 0.0)
|
||||
obj.push_back(Pair("pingwait", stats.dPingWait));
|
||||
obj.push_back(Pair("version", stats.nVersion));
|
||||
// Use the sanitized form of subver here, to avoid tricksy remote peers from
|
||||
// corrupting or modifying the JSON output by putting special characters in
|
||||
// their ver message.
|
||||
obj.push_back(Pair("subver", stats.cleanSubVer));
|
||||
obj.push_back(Pair("inbound", stats.fInbound));
|
||||
obj.push_back(Pair("startingheight", stats.nStartingHeight));
|
||||
if (fStateStats) {
|
||||
obj.push_back(Pair("banscore", statestats.nMisbehavior));
|
||||
obj.push_back(Pair("synced_headers", statestats.nSyncHeight));
|
||||
obj.push_back(Pair("synced_blocks", statestats.nCommonHeight));
|
||||
UniValue heights(UniValue::VARR);
|
||||
BOOST_FOREACH(int height, statestats.vHeightInFlight) {
|
||||
heights.push_back(height);
|
||||
}
|
||||
obj.push_back(Pair("inflight", heights));
|
||||
}
|
||||
obj.push_back(Pair("whitelisted", stats.fWhitelisted));
|
||||
|
||||
ret.push_back(obj);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t KOMODO_LONGESTCHAIN;
|
||||
int32_t komodo_longestchain()
|
||||
{
|
||||
static int32_t depth;
|
||||
int32_t ht,n=0,num=0,maxheight=0,height = 0;
|
||||
if ( depth < 0 )
|
||||
depth = 0;
|
||||
if ( depth == 0 )
|
||||
{
|
||||
depth++;
|
||||
vector<CNodeStats> vstats;
|
||||
{
|
||||
//LOCK(cs_main);
|
||||
CopyNodeStats(vstats);
|
||||
}
|
||||
BOOST_FOREACH(const CNodeStats& stats, vstats)
|
||||
{
|
||||
//fprintf(stderr,"komodo_longestchain iter.%d\n",n);
|
||||
CNodeStateStats statestats;
|
||||
bool fStateStats = GetNodeStateStats(stats.nodeid,statestats);
|
||||
if ( statestats.nSyncHeight < 0 )
|
||||
continue;
|
||||
ht = 0;
|
||||
if ( stats.nStartingHeight > ht )
|
||||
ht = stats.nStartingHeight;
|
||||
if ( statestats.nSyncHeight > ht )
|
||||
ht = statestats.nSyncHeight;
|
||||
if ( statestats.nCommonHeight > ht )
|
||||
ht = statestats.nCommonHeight;
|
||||
if ( maxheight == 0 || ht > maxheight*1.01 )
|
||||
maxheight = ht, num = 1;
|
||||
else if ( ht > maxheight*0.99 )
|
||||
num++;
|
||||
if ( ht > height )
|
||||
height = ht;
|
||||
}
|
||||
depth--;
|
||||
if ( num > (n >> 1) )
|
||||
{
|
||||
extern char ASSETCHAINS_SYMBOL[];
|
||||
if ( 0 && height != KOMODO_LONGESTCHAIN )
|
||||
fprintf(stderr,"set %s KOMODO_LONGESTCHAIN <- %d\n",ASSETCHAINS_SYMBOL,height);
|
||||
KOMODO_LONGESTCHAIN = height;
|
||||
return(height);
|
||||
}
|
||||
KOMODO_LONGESTCHAIN = 0;
|
||||
}
|
||||
return(KOMODO_LONGESTCHAIN);
|
||||
}
|
||||
|
||||
UniValue addnode(const UniValue& params, bool fHelp)
|
||||
{
|
||||
string strCommand;
|
||||
if (params.size() == 2)
|
||||
strCommand = params[1].get_str();
|
||||
if (fHelp || params.size() != 2 ||
|
||||
(strCommand != "onetry" && strCommand != "add" && strCommand != "remove"))
|
||||
throw runtime_error(
|
||||
"addnode \"node\" \"add|remove|onetry\"\n"
|
||||
"\nAttempts add or remove a node from the addnode list.\n"
|
||||
"Or try a connection to a node once.\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"node\" (string, required) The node (see getpeerinfo for nodes)\n"
|
||||
"2. \"command\" (string, required) 'add' to add a node to the list, 'remove' to remove a node from the list, 'onetry' to try a connection to the node once\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("addnode", "\"192.168.0.6:8233\" \"onetry\"")
|
||||
+ HelpExampleRpc("addnode", "\"192.168.0.6:8233\", \"onetry\"")
|
||||
);
|
||||
|
||||
string strNode = params[0].get_str();
|
||||
|
||||
if (strCommand == "onetry")
|
||||
{
|
||||
CAddress addr;
|
||||
OpenNetworkConnection(addr, NULL, strNode.c_str());
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
LOCK(cs_vAddedNodes);
|
||||
vector<string>::iterator it = vAddedNodes.begin();
|
||||
for(; it != vAddedNodes.end(); it++)
|
||||
if (strNode == *it)
|
||||
break;
|
||||
|
||||
if (strCommand == "add")
|
||||
{
|
||||
if (it != vAddedNodes.end())
|
||||
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: Node already added");
|
||||
vAddedNodes.push_back(strNode);
|
||||
}
|
||||
else if(strCommand == "remove")
|
||||
{
|
||||
if (it == vAddedNodes.end())
|
||||
throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node has not been added.");
|
||||
vAddedNodes.erase(it);
|
||||
}
|
||||
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
UniValue disconnectnode(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 1)
|
||||
throw runtime_error(
|
||||
"disconnectnode \"node\" \n"
|
||||
"\nImmediately disconnects from the specified node.\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"node\" (string, required) The node (see getpeerinfo for nodes)\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("disconnectnode", "\"192.168.0.6:8233\"")
|
||||
+ HelpExampleRpc("disconnectnode", "\"192.168.0.6:8233\"")
|
||||
);
|
||||
|
||||
CNode* pNode = FindNode(params[0].get_str());
|
||||
if (pNode == NULL)
|
||||
throw JSONRPCError(RPC_CLIENT_NODE_NOT_CONNECTED, "Node not found in connected nodes");
|
||||
|
||||
pNode->fDisconnect = true;
|
||||
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
UniValue getaddednodeinfo(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() < 1 || params.size() > 2)
|
||||
throw runtime_error(
|
||||
"getaddednodeinfo dns ( \"node\" )\n"
|
||||
"\nReturns information about the given added node, or all added nodes\n"
|
||||
"(note that onetry addnodes are not listed here)\n"
|
||||
"If dns is false, only a list of added nodes will be provided,\n"
|
||||
"otherwise connected information will also be available.\n"
|
||||
"\nArguments:\n"
|
||||
"1. dns (boolean, required) If false, only a list of added nodes will be provided, otherwise connected information will also be available.\n"
|
||||
"2. \"node\" (string, optional) If provided, return information about this specific node, otherwise all nodes are returned.\n"
|
||||
"\nResult:\n"
|
||||
"[\n"
|
||||
" {\n"
|
||||
" \"addednode\" : \"192.168.0.201\", (string) The node ip address\n"
|
||||
" \"connected\" : true|false, (boolean) If connected\n"
|
||||
" \"addresses\" : [\n"
|
||||
" {\n"
|
||||
" \"address\" : \"192.168.0.201:8233\", (string) The Komodo server host and port\n"
|
||||
" \"connected\" : \"outbound\" (string) connection, inbound or outbound\n"
|
||||
" }\n"
|
||||
" ,...\n"
|
||||
" ]\n"
|
||||
" }\n"
|
||||
" ,...\n"
|
||||
"]\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("getaddednodeinfo", "true")
|
||||
+ HelpExampleCli("getaddednodeinfo", "true \"192.168.0.201\"")
|
||||
+ HelpExampleRpc("getaddednodeinfo", "true, \"192.168.0.201\"")
|
||||
);
|
||||
|
||||
bool fDns = params[0].get_bool();
|
||||
|
||||
list<string> laddedNodes(0);
|
||||
if (params.size() == 1)
|
||||
{
|
||||
LOCK(cs_vAddedNodes);
|
||||
BOOST_FOREACH(const std::string& strAddNode, vAddedNodes)
|
||||
laddedNodes.push_back(strAddNode);
|
||||
}
|
||||
else
|
||||
{
|
||||
string strNode = params[1].get_str();
|
||||
LOCK(cs_vAddedNodes);
|
||||
BOOST_FOREACH(const std::string& strAddNode, vAddedNodes) {
|
||||
if (strAddNode == strNode)
|
||||
{
|
||||
laddedNodes.push_back(strAddNode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (laddedNodes.size() == 0)
|
||||
throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node has not been added.");
|
||||
}
|
||||
|
||||
UniValue ret(UniValue::VARR);
|
||||
if (!fDns)
|
||||
{
|
||||
BOOST_FOREACH (const std::string& strAddNode, laddedNodes) {
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.push_back(Pair("addednode", strAddNode));
|
||||
ret.push_back(obj);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
list<pair<string, vector<CService> > > laddedAddreses(0);
|
||||
BOOST_FOREACH(const std::string& strAddNode, laddedNodes) {
|
||||
vector<CService> vservNode(0);
|
||||
if(Lookup(strAddNode.c_str(), vservNode, Params().GetDefaultPort(), fNameLookup, 0))
|
||||
laddedAddreses.push_back(make_pair(strAddNode, vservNode));
|
||||
else
|
||||
{
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.push_back(Pair("addednode", strAddNode));
|
||||
obj.push_back(Pair("connected", false));
|
||||
UniValue addresses(UniValue::VARR);
|
||||
obj.push_back(Pair("addresses", addresses));
|
||||
}
|
||||
}
|
||||
|
||||
LOCK(cs_vNodes);
|
||||
for (list<pair<string, vector<CService> > >::iterator it = laddedAddreses.begin(); it != laddedAddreses.end(); it++)
|
||||
{
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.push_back(Pair("addednode", it->first));
|
||||
|
||||
UniValue addresses(UniValue::VARR);
|
||||
bool fConnected = false;
|
||||
BOOST_FOREACH(const CService& addrNode, it->second) {
|
||||
bool fFound = false;
|
||||
UniValue node(UniValue::VOBJ);
|
||||
node.push_back(Pair("address", addrNode.ToString()));
|
||||
BOOST_FOREACH(CNode* pnode, vNodes) {
|
||||
if (pnode->addr == addrNode)
|
||||
{
|
||||
fFound = true;
|
||||
fConnected = true;
|
||||
node.push_back(Pair("connected", pnode->fInbound ? "inbound" : "outbound"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!fFound)
|
||||
node.push_back(Pair("connected", "false"));
|
||||
addresses.push_back(node);
|
||||
}
|
||||
obj.push_back(Pair("connected", fConnected));
|
||||
obj.push_back(Pair("addresses", addresses));
|
||||
ret.push_back(obj);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
UniValue getnettotals(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() > 0)
|
||||
throw runtime_error(
|
||||
"getnettotals\n"
|
||||
"\nReturns information about network traffic, including bytes in, bytes out,\n"
|
||||
"and current time.\n"
|
||||
"\nResult:\n"
|
||||
"{\n"
|
||||
" \"totalbytesrecv\": n, (numeric) Total bytes received\n"
|
||||
" \"totalbytessent\": n, (numeric) Total bytes sent\n"
|
||||
" \"timemillis\": t (numeric) Total cpu time\n"
|
||||
"}\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("getnettotals", "")
|
||||
+ HelpExampleRpc("getnettotals", "")
|
||||
);
|
||||
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.push_back(Pair("totalbytesrecv", CNode::GetTotalBytesRecv()));
|
||||
obj.push_back(Pair("totalbytessent", CNode::GetTotalBytesSent()));
|
||||
obj.push_back(Pair("timemillis", GetTimeMillis()));
|
||||
return obj;
|
||||
}
|
||||
|
||||
static UniValue GetNetworksInfo()
|
||||
{
|
||||
UniValue networks(UniValue::VARR);
|
||||
for(int n=0; n<NET_MAX; ++n)
|
||||
{
|
||||
enum Network network = static_cast<enum Network>(n);
|
||||
if(network == NET_UNROUTABLE)
|
||||
continue;
|
||||
proxyType proxy;
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
GetProxy(network, proxy);
|
||||
obj.push_back(Pair("name", GetNetworkName(network)));
|
||||
obj.push_back(Pair("limited", IsLimited(network)));
|
||||
obj.push_back(Pair("reachable", IsReachable(network)));
|
||||
obj.push_back(Pair("proxy", proxy.IsValid() ? proxy.proxy.ToStringIPPort() : string()));
|
||||
obj.push_back(Pair("proxy_randomize_credentials", proxy.randomize_credentials));
|
||||
networks.push_back(obj);
|
||||
}
|
||||
return networks;
|
||||
}
|
||||
|
||||
UniValue getdeprecationinfo(const UniValue& params, bool fHelp)
|
||||
{
|
||||
const CChainParams& chainparams = Params();
|
||||
if (fHelp || params.size() != 0 || chainparams.NetworkIDString() != "main")
|
||||
throw runtime_error(
|
||||
"getdeprecationinfo\n"
|
||||
"Returns an object containing current version and deprecation block height. Applicable only on mainnet.\n"
|
||||
"\nResult:\n"
|
||||
"{\n"
|
||||
" \"version\": xxxxx, (numeric) the server version\n"
|
||||
" \"subversion\": \"/MagicBean:x.y.z[-v]/\", (string) the server subversion string\n"
|
||||
" \"deprecationheight\": xxxxx, (numeric) the block height at which this version will deprecate and shut down (unless -disabledeprecation is set)\n"
|
||||
"}\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("getdeprecationinfo", "")
|
||||
+ HelpExampleRpc("getdeprecationinfo", "")
|
||||
);
|
||||
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.push_back(Pair("version", CLIENT_VERSION));
|
||||
obj.push_back(Pair("subversion",
|
||||
FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, std::vector<string>())));
|
||||
obj.push_back(Pair("deprecationheight", DEPRECATION_HEIGHT));
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
UniValue getnetworkinfo(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
throw runtime_error(
|
||||
"getnetworkinfo\n"
|
||||
"Returns an object containing various state info regarding P2P networking.\n"
|
||||
"\nResult:\n"
|
||||
"{\n"
|
||||
" \"version\": xxxxx, (numeric) the server version\n"
|
||||
" \"subversion\": \"/MagicBean:x.y.z[-v]/\", (string) the server subversion string\n"
|
||||
" \"protocolversion\": xxxxx, (numeric) the protocol version\n"
|
||||
" \"localservices\": \"xxxxxxxxxxxxxxxx\", (string) the services we offer to the network\n"
|
||||
" \"timeoffset\": xxxxx, (numeric) the time offset\n"
|
||||
" \"connections\": xxxxx, (numeric) the number of connections\n"
|
||||
" \"networks\": [ (array) information per network\n"
|
||||
" {\n"
|
||||
" \"name\": \"xxx\", (string) network (ipv4, ipv6 or onion)\n"
|
||||
" \"limited\": true|false, (boolean) is the network limited using -onlynet?\n"
|
||||
" \"reachable\": true|false, (boolean) is the network reachable?\n"
|
||||
" \"proxy\": \"host:port\" (string) the proxy that is used for this network, or empty if none\n"
|
||||
" }\n"
|
||||
" ,...\n"
|
||||
" ],\n"
|
||||
" \"relayfee\": x.xxxxxxxx, (numeric) minimum relay fee for non-free transactions in " + CURRENCY_UNIT + "/kB\n"
|
||||
" \"localaddresses\": [ (array) list of local addresses\n"
|
||||
" {\n"
|
||||
" \"address\": \"xxxx\", (string) network address\n"
|
||||
" \"port\": xxx, (numeric) network port\n"
|
||||
" \"score\": xxx (numeric) relative score\n"
|
||||
" }\n"
|
||||
" ,...\n"
|
||||
" ]\n"
|
||||
" \"warnings\": \"...\" (string) any network warnings (such as alert messages) \n"
|
||||
"}\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("getnetworkinfo", "")
|
||||
+ HelpExampleRpc("getnetworkinfo", "")
|
||||
);
|
||||
|
||||
LOCK(cs_main);
|
||||
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.push_back(Pair("version", CLIENT_VERSION));
|
||||
obj.push_back(Pair("subversion",
|
||||
FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, std::vector<string>())));
|
||||
obj.push_back(Pair("protocolversion",PROTOCOL_VERSION));
|
||||
obj.push_back(Pair("localservices", strprintf("%016x", nLocalServices)));
|
||||
obj.push_back(Pair("timeoffset", GetTimeOffset()));
|
||||
obj.push_back(Pair("connections", (int)vNodes.size()));
|
||||
obj.push_back(Pair("networks", GetNetworksInfo()));
|
||||
obj.push_back(Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK())));
|
||||
UniValue localAddresses(UniValue::VARR);
|
||||
{
|
||||
LOCK(cs_mapLocalHost);
|
||||
BOOST_FOREACH(const PAIRTYPE(CNetAddr, LocalServiceInfo) &item, mapLocalHost)
|
||||
{
|
||||
UniValue rec(UniValue::VOBJ);
|
||||
rec.push_back(Pair("address", item.first.ToString()));
|
||||
rec.push_back(Pair("port", item.second.nPort));
|
||||
rec.push_back(Pair("score", item.second.nScore));
|
||||
localAddresses.push_back(rec);
|
||||
}
|
||||
}
|
||||
obj.push_back(Pair("localaddresses", localAddresses));
|
||||
obj.push_back(Pair("warnings", GetWarnings("statusbar")));
|
||||
return obj;
|
||||
}
|
||||
|
||||
UniValue setban(const UniValue& params, bool fHelp)
|
||||
{
|
||||
string strCommand;
|
||||
if (params.size() >= 2)
|
||||
strCommand = params[1].get_str();
|
||||
if (fHelp || params.size() < 2 ||
|
||||
(strCommand != "add" && strCommand != "remove"))
|
||||
throw runtime_error(
|
||||
"setban \"ip(/netmask)\" \"add|remove\" (bantime) (absolute)\n"
|
||||
"\nAttempts add or remove a IP/Subnet from the banned list.\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"ip(/netmask)\" (string, required) The IP/Subnet (see getpeerinfo for nodes ip) with a optional netmask (default is /32 = single ip)\n"
|
||||
"2. \"command\" (string, required) 'add' to add a IP/Subnet to the list, 'remove' to remove a IP/Subnet from the list\n"
|
||||
"3. \"bantime\" (numeric, optional) time in seconds how long (or until when if [absolute] is set) the ip is banned (0 or empty means using the default time of 24h which can also be overwritten by the -bantime startup argument)\n"
|
||||
"4. \"absolute\" (boolean, optional) If set, the bantime must be a absolute timestamp in seconds since epoch (Jan 1 1970 GMT)\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("setban", "\"192.168.0.6\" \"add\" 86400")
|
||||
+ HelpExampleCli("setban", "\"192.168.0.0/24\" \"add\"")
|
||||
+ HelpExampleRpc("setban", "\"192.168.0.6\", \"add\" 86400")
|
||||
);
|
||||
|
||||
CSubNet subNet;
|
||||
CNetAddr netAddr;
|
||||
bool isSubnet = false;
|
||||
|
||||
if (params[0].get_str().find("/") != string::npos)
|
||||
isSubnet = true;
|
||||
|
||||
if (!isSubnet)
|
||||
netAddr = CNetAddr(params[0].get_str());
|
||||
else
|
||||
subNet = CSubNet(params[0].get_str());
|
||||
|
||||
if (! (isSubnet ? subNet.IsValid() : netAddr.IsValid()) )
|
||||
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: Invalid IP/Subnet");
|
||||
|
||||
if (strCommand == "add")
|
||||
{
|
||||
if (isSubnet ? CNode::IsBanned(subNet) : CNode::IsBanned(netAddr))
|
||||
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: IP/Subnet already banned");
|
||||
|
||||
int64_t banTime = 0; //use standard bantime if not specified
|
||||
if (params.size() >= 3 && !params[2].isNull())
|
||||
banTime = params[2].get_int64();
|
||||
|
||||
bool absolute = false;
|
||||
if (params.size() == 4 && params[3].isTrue())
|
||||
absolute = true;
|
||||
|
||||
isSubnet ? CNode::Ban(subNet, banTime, absolute) : CNode::Ban(netAddr, banTime, absolute);
|
||||
|
||||
//disconnect possible nodes
|
||||
while(CNode *bannedNode = (isSubnet ? FindNode(subNet) : FindNode(netAddr)))
|
||||
bannedNode->fDisconnect = true;
|
||||
}
|
||||
else if(strCommand == "remove")
|
||||
{
|
||||
if (!( isSubnet ? CNode::Unban(subNet) : CNode::Unban(netAddr) ))
|
||||
throw JSONRPCError(RPC_MISC_ERROR, "Error: Unban failed");
|
||||
}
|
||||
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
UniValue listbanned(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
throw runtime_error(
|
||||
"listbanned\n"
|
||||
"\nList all banned IPs/Subnets.\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("listbanned", "")
|
||||
+ HelpExampleRpc("listbanned", "")
|
||||
);
|
||||
|
||||
std::map<CSubNet, int64_t> banMap;
|
||||
CNode::GetBanned(banMap);
|
||||
|
||||
UniValue bannedAddresses(UniValue::VARR);
|
||||
for (std::map<CSubNet, int64_t>::iterator it = banMap.begin(); it != banMap.end(); it++)
|
||||
{
|
||||
UniValue rec(UniValue::VOBJ);
|
||||
rec.push_back(Pair("address", (*it).first.ToString()));
|
||||
rec.push_back(Pair("banned_until", (*it).second));
|
||||
bannedAddresses.push_back(rec);
|
||||
}
|
||||
|
||||
return bannedAddresses;
|
||||
}
|
||||
|
||||
UniValue clearbanned(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 0)
|
||||
throw runtime_error(
|
||||
"clearbanned\n"
|
||||
"\nClear all banned IPs.\n"
|
||||
"\nExamples:\n"
|
||||
+ HelpExampleCli("clearbanned", "")
|
||||
+ HelpExampleRpc("clearbanned", "")
|
||||
);
|
||||
|
||||
CNode::ClearBanned();
|
||||
|
||||
return NullUniValue;
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
// Copyright (c) 2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2014 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "rpcprotocol.h"
|
||||
|
||||
#include "random.h"
|
||||
#include "tinyformat.h"
|
||||
#include "util.h"
|
||||
#include "utilstrencodings.h"
|
||||
#include "utiltime.h"
|
||||
#include "version.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* JSON-RPC protocol. Bitcoin speaks version 1.0 for maximum compatibility,
|
||||
* but uses JSON-RPC 1.1/2.0 standards for parts of the 1.0 standard that were
|
||||
* unspecified (HTTP errors and contents of 'error').
|
||||
*
|
||||
* 1.0 spec: http://json-rpc.org/wiki/specification
|
||||
* 1.2 spec: http://jsonrpc.org/historical/json-rpc-over-http.html
|
||||
*/
|
||||
|
||||
string JSONRPCRequest(const string& strMethod, const UniValue& params, const UniValue& id)
|
||||
{
|
||||
UniValue request(UniValue::VOBJ);
|
||||
request.push_back(Pair("method", strMethod));
|
||||
request.push_back(Pair("params", params));
|
||||
request.push_back(Pair("id", id));
|
||||
return request.write() + "\n";
|
||||
}
|
||||
|
||||
UniValue JSONRPCReplyObj(const UniValue& result, const UniValue& error, const UniValue& id)
|
||||
{
|
||||
UniValue reply(UniValue::VOBJ);
|
||||
if (!error.isNull())
|
||||
reply.push_back(Pair("result", NullUniValue));
|
||||
else
|
||||
reply.push_back(Pair("result", result));
|
||||
reply.push_back(Pair("error", error));
|
||||
reply.push_back(Pair("id", id));
|
||||
return reply;
|
||||
}
|
||||
|
||||
string JSONRPCReply(const UniValue& result, const UniValue& error, const UniValue& id)
|
||||
{
|
||||
UniValue reply = JSONRPCReplyObj(result, error, id);
|
||||
return reply.write() + "\n";
|
||||
}
|
||||
|
||||
UniValue JSONRPCError(int code, const string& message)
|
||||
{
|
||||
UniValue error(UniValue::VOBJ);
|
||||
error.push_back(Pair("code", code));
|
||||
error.push_back(Pair("message", message));
|
||||
return error;
|
||||
}
|
||||
|
||||
/** Username used when cookie authentication is in use (arbitrary, only for
|
||||
* recognizability in debugging/logging purposes)
|
||||
*/
|
||||
static const std::string COOKIEAUTH_USER = "__cookie__";
|
||||
/** Default name for auth cookie file */
|
||||
static const std::string COOKIEAUTH_FILE = ".cookie";
|
||||
|
||||
boost::filesystem::path GetAuthCookieFile()
|
||||
{
|
||||
boost::filesystem::path path(GetArg("-rpccookiefile", COOKIEAUTH_FILE));
|
||||
if (!path.is_complete()) path = GetDataDir() / path;
|
||||
return path;
|
||||
}
|
||||
|
||||
bool GenerateAuthCookie(std::string *cookie_out)
|
||||
{
|
||||
unsigned char rand_pwd[32];
|
||||
GetRandBytes(rand_pwd, 32);
|
||||
std::string cookie = COOKIEAUTH_USER + ":" + EncodeBase64(&rand_pwd[0],32);
|
||||
|
||||
/** the umask determines what permissions are used to create this file -
|
||||
* these are set to 077 in init.cpp unless overridden with -sysperms.
|
||||
*/
|
||||
std::ofstream file;
|
||||
boost::filesystem::path filepath = GetAuthCookieFile();
|
||||
file.open(filepath.string().c_str());
|
||||
if (!file.is_open()) {
|
||||
LogPrintf("Unable to open cookie authentication file %s for writing\n", filepath.string());
|
||||
return false;
|
||||
}
|
||||
file << cookie;
|
||||
file.close();
|
||||
LogPrintf("Generated RPC authentication cookie %s\n", filepath.string());
|
||||
|
||||
if (cookie_out)
|
||||
*cookie_out = cookie;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GetAuthCookie(std::string *cookie_out)
|
||||
{
|
||||
std::ifstream file;
|
||||
std::string cookie;
|
||||
boost::filesystem::path filepath = GetAuthCookieFile();
|
||||
file.open(filepath.string().c_str());
|
||||
if (!file.is_open())
|
||||
return false;
|
||||
std::getline(file, cookie);
|
||||
file.close();
|
||||
|
||||
if (cookie_out)
|
||||
*cookie_out = cookie;
|
||||
return true;
|
||||
}
|
||||
|
||||
void DeleteAuthCookie()
|
||||
{
|
||||
try {
|
||||
boost::filesystem::remove(GetAuthCookieFile());
|
||||
} catch (const boost::filesystem::filesystem_error& e) {
|
||||
LogPrintf("%s: Unable to remove random auth cookie file: %s\n", __func__, e.what());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
// Copyright (c) 2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2014 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_RPCPROTOCOL_H
|
||||
#define BITCOIN_RPCPROTOCOL_H
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <univalue.h>
|
||||
|
||||
//! HTTP status codes
|
||||
enum HTTPStatusCode
|
||||
{
|
||||
HTTP_OK = 200,
|
||||
HTTP_BAD_REQUEST = 400,
|
||||
HTTP_UNAUTHORIZED = 401,
|
||||
HTTP_FORBIDDEN = 403,
|
||||
HTTP_NOT_FOUND = 404,
|
||||
HTTP_BAD_METHOD = 405,
|
||||
HTTP_INTERNAL_SERVER_ERROR = 500,
|
||||
HTTP_SERVICE_UNAVAILABLE = 503,
|
||||
};
|
||||
|
||||
//! Bitcoin RPC error codes
|
||||
enum RPCErrorCode
|
||||
{
|
||||
//! Standard JSON-RPC 2.0 errors
|
||||
RPC_INVALID_REQUEST = -32600,
|
||||
RPC_METHOD_NOT_FOUND = -32601,
|
||||
RPC_INVALID_PARAMS = -32602,
|
||||
RPC_INTERNAL_ERROR = -32603,
|
||||
RPC_PARSE_ERROR = -32700,
|
||||
|
||||
//! General application defined errors
|
||||
RPC_MISC_ERROR = -1, //! std::exception thrown in command handling
|
||||
RPC_FORBIDDEN_BY_SAFE_MODE = -2, //! Server is in safe mode, and command is not allowed in safe mode
|
||||
RPC_TYPE_ERROR = -3, //! Unexpected type was passed as parameter
|
||||
RPC_INVALID_ADDRESS_OR_KEY = -5, //! Invalid address or key
|
||||
RPC_OUT_OF_MEMORY = -7, //! Ran out of memory during operation
|
||||
RPC_INVALID_PARAMETER = -8, //! Invalid, missing or duplicate parameter
|
||||
RPC_DATABASE_ERROR = -20, //! Database error
|
||||
RPC_DESERIALIZATION_ERROR = -22, //! Error parsing or validating structure in raw format
|
||||
RPC_VERIFY_ERROR = -25, //! General error during transaction or block submission
|
||||
RPC_VERIFY_REJECTED = -26, //! Transaction or block was rejected by network rules
|
||||
RPC_VERIFY_ALREADY_IN_CHAIN = -27, //! Transaction already in chain
|
||||
RPC_IN_WARMUP = -28, //! Client still warming up
|
||||
|
||||
//! Aliases for backward compatibility
|
||||
RPC_TRANSACTION_ERROR = RPC_VERIFY_ERROR,
|
||||
RPC_TRANSACTION_REJECTED = RPC_VERIFY_REJECTED,
|
||||
RPC_TRANSACTION_ALREADY_IN_CHAIN= RPC_VERIFY_ALREADY_IN_CHAIN,
|
||||
|
||||
//! P2P client errors
|
||||
RPC_CLIENT_NOT_CONNECTED = -9, //! Bitcoin is not connected
|
||||
RPC_CLIENT_IN_INITIAL_DOWNLOAD = -10, //! Still downloading initial blocks
|
||||
RPC_CLIENT_NODE_ALREADY_ADDED = -23, //! Node is already added
|
||||
RPC_CLIENT_NODE_NOT_ADDED = -24, //! Node has not been added before
|
||||
RPC_CLIENT_NODE_NOT_CONNECTED = -29, //! Node to disconnect not found in connected nodes
|
||||
RPC_CLIENT_INVALID_IP_OR_SUBNET = -30, //! Invalid IP/Subnet
|
||||
|
||||
//! Wallet errors
|
||||
RPC_WALLET_ERROR = -4, //! Unspecified problem with wallet (key not found etc.)
|
||||
RPC_WALLET_INSUFFICIENT_FUNDS = -6, //! Not enough funds in wallet or account
|
||||
RPC_WALLET_ACCOUNTS_UNSUPPORTED = -11, //! Accounts are unsupported
|
||||
RPC_WALLET_KEYPOOL_RAN_OUT = -12, //! Keypool ran out, call keypoolrefill first
|
||||
RPC_WALLET_UNLOCK_NEEDED = -13, //! Enter the wallet passphrase with walletpassphrase first
|
||||
RPC_WALLET_PASSPHRASE_INCORRECT = -14, //! The wallet passphrase entered was incorrect
|
||||
RPC_WALLET_WRONG_ENC_STATE = -15, //! Command given in wrong wallet encryption state (encrypting an encrypted wallet etc.)
|
||||
RPC_WALLET_ENCRYPTION_FAILED = -16, //! Failed to encrypt the wallet
|
||||
RPC_WALLET_ALREADY_UNLOCKED = -17, //! Wallet is already unlocked
|
||||
};
|
||||
|
||||
std::string JSONRPCRequest(const std::string& strMethod, const UniValue& params, const UniValue& id);
|
||||
UniValue JSONRPCReplyObj(const UniValue& result, const UniValue& error, const UniValue& id);
|
||||
std::string JSONRPCReply(const UniValue& result, const UniValue& error, const UniValue& id);
|
||||
UniValue JSONRPCError(int code, const std::string& message);
|
||||
|
||||
/** Get name of RPC authentication cookie file */
|
||||
boost::filesystem::path GetAuthCookieFile();
|
||||
/** Generate a new RPC authentication cookie and write it to disk */
|
||||
bool GenerateAuthCookie(std::string *cookie_out);
|
||||
/** Read the RPC authentication cookie from disk */
|
||||
bool GetAuthCookie(std::string *cookie_out);
|
||||
/** Delete RPC authentication cookie from disk */
|
||||
void DeleteAuthCookie();
|
||||
|
||||
#endif // BITCOIN_RPCPROTOCOL_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,778 +0,0 @@
|
||||
// Copyright (c) 2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2014 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "rpcserver.h"
|
||||
|
||||
#include "base58.h"
|
||||
#include "init.h"
|
||||
#include "random.h"
|
||||
#include "sync.h"
|
||||
#include "ui_interface.h"
|
||||
#include "util.h"
|
||||
#include "utilstrencodings.h"
|
||||
#include "asyncrpcqueue.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <univalue.h>
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/iostreams/concepts.hpp>
|
||||
#include <boost/iostreams/stream.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/signals2/signal.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/algorithm/string/case_conv.hpp> // for to_upper()
|
||||
|
||||
using namespace RPCServer;
|
||||
using namespace std;
|
||||
|
||||
static bool fRPCRunning = false;
|
||||
static bool fRPCInWarmup = true;
|
||||
static std::string rpcWarmupStatus("RPC server started");
|
||||
static CCriticalSection cs_rpcWarmup;
|
||||
/* Timer-creating functions */
|
||||
static std::vector<RPCTimerInterface*> timerInterfaces;
|
||||
/* Map of name to timer.
|
||||
* @note Can be changed to std::unique_ptr when C++11 */
|
||||
static std::map<std::string, boost::shared_ptr<RPCTimerBase> > deadlineTimers;
|
||||
|
||||
static struct CRPCSignals
|
||||
{
|
||||
boost::signals2::signal<void ()> Started;
|
||||
boost::signals2::signal<void ()> Stopped;
|
||||
boost::signals2::signal<void (const CRPCCommand&)> PreCommand;
|
||||
boost::signals2::signal<void (const CRPCCommand&)> PostCommand;
|
||||
} g_rpcSignals;
|
||||
|
||||
void RPCServer::OnStarted(boost::function<void ()> slot)
|
||||
{
|
||||
g_rpcSignals.Started.connect(slot);
|
||||
}
|
||||
|
||||
void RPCServer::OnStopped(boost::function<void ()> slot)
|
||||
{
|
||||
g_rpcSignals.Stopped.connect(slot);
|
||||
}
|
||||
|
||||
void RPCServer::OnPreCommand(boost::function<void (const CRPCCommand&)> slot)
|
||||
{
|
||||
g_rpcSignals.PreCommand.connect(boost::bind(slot, _1));
|
||||
}
|
||||
|
||||
void RPCServer::OnPostCommand(boost::function<void (const CRPCCommand&)> slot)
|
||||
{
|
||||
g_rpcSignals.PostCommand.connect(boost::bind(slot, _1));
|
||||
}
|
||||
|
||||
void RPCTypeCheck(const UniValue& params,
|
||||
const list<UniValue::VType>& typesExpected,
|
||||
bool fAllowNull)
|
||||
{
|
||||
size_t i = 0;
|
||||
BOOST_FOREACH(UniValue::VType t, typesExpected)
|
||||
{
|
||||
if (params.size() <= i)
|
||||
break;
|
||||
|
||||
const UniValue& v = params[i];
|
||||
if (!((v.type() == t) || (fAllowNull && (v.isNull()))))
|
||||
{
|
||||
string err = strprintf("Expected type %s, got %s",
|
||||
uvTypeName(t), uvTypeName(v.type()));
|
||||
throw JSONRPCError(RPC_TYPE_ERROR, err);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void RPCTypeCheckObj(const UniValue& o,
|
||||
const map<string, UniValue::VType>& typesExpected,
|
||||
bool fAllowNull)
|
||||
{
|
||||
BOOST_FOREACH(const PAIRTYPE(string, UniValue::VType)& t, typesExpected)
|
||||
{
|
||||
const UniValue& v = find_value(o, t.first);
|
||||
if (!fAllowNull && v.isNull())
|
||||
throw JSONRPCError(RPC_TYPE_ERROR, strprintf("Missing %s", t.first));
|
||||
|
||||
if (!((v.type() == t.second) || (fAllowNull && (v.isNull()))))
|
||||
{
|
||||
string err = strprintf("Expected type %s for %s, got %s",
|
||||
uvTypeName(t.second), t.first, uvTypeName(v.type()));
|
||||
throw JSONRPCError(RPC_TYPE_ERROR, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CAmount AmountFromValue(const UniValue& value)
|
||||
{
|
||||
if (!value.isNum() && !value.isStr())
|
||||
throw JSONRPCError(RPC_TYPE_ERROR, "Amount is not a number or string");
|
||||
CAmount amount;
|
||||
if (!ParseFixedPoint(value.getValStr(), 8, &amount))
|
||||
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount");
|
||||
if (!MoneyRange(amount))
|
||||
throw JSONRPCError(RPC_TYPE_ERROR, "Amount out of range");
|
||||
return amount;
|
||||
}
|
||||
|
||||
UniValue ValueFromAmount(const CAmount& amount)
|
||||
{
|
||||
bool sign = amount < 0;
|
||||
int64_t n_abs = (sign ? -amount : amount);
|
||||
int64_t quotient = n_abs / COIN;
|
||||
int64_t remainder = n_abs % COIN;
|
||||
return UniValue(UniValue::VNUM,
|
||||
strprintf("%s%d.%08d", sign ? "-" : "", quotient, remainder));
|
||||
}
|
||||
|
||||
uint256 ParseHashV(const UniValue& v, string strName)
|
||||
{
|
||||
string strHex;
|
||||
if (v.isStr())
|
||||
strHex = v.get_str();
|
||||
if (!IsHex(strHex)) // Note: IsHex("") is false
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be hexadecimal string (not '"+strHex+"')");
|
||||
uint256 result;
|
||||
result.SetHex(strHex);
|
||||
return result;
|
||||
}
|
||||
uint256 ParseHashO(const UniValue& o, string strKey)
|
||||
{
|
||||
return ParseHashV(find_value(o, strKey), strKey);
|
||||
}
|
||||
vector<unsigned char> ParseHexV(const UniValue& v, string strName)
|
||||
{
|
||||
string strHex;
|
||||
if (v.isStr())
|
||||
strHex = v.get_str();
|
||||
if (!IsHex(strHex))
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, strName+" must be hexadecimal string (not '"+strHex+"')");
|
||||
return ParseHex(strHex);
|
||||
}
|
||||
vector<unsigned char> ParseHexO(const UniValue& o, string strKey)
|
||||
{
|
||||
return ParseHexV(find_value(o, strKey), strKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: This interface may still be subject to change.
|
||||
*/
|
||||
|
||||
std::string CRPCTable::help(const std::string& strCommand) const
|
||||
{
|
||||
string strRet;
|
||||
string category;
|
||||
set<rpcfn_type> setDone;
|
||||
vector<pair<string, const CRPCCommand*> > vCommands;
|
||||
|
||||
for (map<string, const CRPCCommand*>::const_iterator mi = mapCommands.begin(); mi != mapCommands.end(); ++mi)
|
||||
vCommands.push_back(make_pair(mi->second->category + mi->first, mi->second));
|
||||
sort(vCommands.begin(), vCommands.end());
|
||||
|
||||
BOOST_FOREACH(const PAIRTYPE(string, const CRPCCommand*)& command, vCommands)
|
||||
{
|
||||
const CRPCCommand *pcmd = command.second;
|
||||
string strMethod = pcmd->name;
|
||||
// We already filter duplicates, but these deprecated screw up the sort order
|
||||
if (strMethod.find("label") != string::npos)
|
||||
continue;
|
||||
if ((strCommand != "" || pcmd->category == "hidden") && strMethod != strCommand)
|
||||
continue;
|
||||
try
|
||||
{
|
||||
UniValue params;
|
||||
rpcfn_type pfn = pcmd->actor;
|
||||
if (setDone.insert(pfn).second)
|
||||
(*pfn)(params, true);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
// Help text is returned in an exception
|
||||
string strHelp = string(e.what());
|
||||
if (strCommand == "")
|
||||
{
|
||||
if (strHelp.find('\n') != string::npos)
|
||||
strHelp = strHelp.substr(0, strHelp.find('\n'));
|
||||
|
||||
if (category != pcmd->category)
|
||||
{
|
||||
if (!category.empty())
|
||||
strRet += "\n";
|
||||
category = pcmd->category;
|
||||
string firstLetter = category.substr(0,1);
|
||||
boost::to_upper(firstLetter);
|
||||
strRet += "== " + firstLetter + category.substr(1) + " ==\n";
|
||||
}
|
||||
}
|
||||
strRet += strHelp + "\n";
|
||||
}
|
||||
}
|
||||
if (strRet == "")
|
||||
strRet = strprintf("help: unknown command: %s\n", strCommand);
|
||||
strRet = strRet.substr(0,strRet.size()-1);
|
||||
return strRet;
|
||||
}
|
||||
|
||||
UniValue help(const UniValue& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() > 1)
|
||||
throw runtime_error(
|
||||
"help ( \"command\" )\n"
|
||||
"\nList all commands, or get help for a specified command.\n"
|
||||
"\nArguments:\n"
|
||||
"1. \"command\" (string, optional) The command to get help on\n"
|
||||
"\nResult:\n"
|
||||
"\"text\" (string) The help text\n"
|
||||
);
|
||||
|
||||
string strCommand;
|
||||
if (params.size() > 0)
|
||||
strCommand = params[0].get_str();
|
||||
|
||||
return tableRPC.help(strCommand);
|
||||
}
|
||||
|
||||
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
|
||||
|
||||
UniValue stop(const UniValue& params, bool fHelp)
|
||||
{
|
||||
char buf[66+128];
|
||||
// Accept the deprecated and ignored 'detach' boolean argument
|
||||
if (fHelp || params.size() > 1)
|
||||
throw runtime_error(
|
||||
"stop\n"
|
||||
"\nStop Komodo server.");
|
||||
// Shutdown will take long enough that the response should get back
|
||||
StartShutdown();
|
||||
sprintf(buf,"%s server stopping",ASSETCHAINS_SYMBOL[0] != 0 ? ASSETCHAINS_SYMBOL : "Komodo");
|
||||
return buf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call Table
|
||||
*/
|
||||
static const CRPCCommand vRPCCommands[] =
|
||||
{ // category name actor (function) okSafeMode
|
||||
// --------------------- ------------------------ ----------------------- ----------
|
||||
/* Overall control/query calls */
|
||||
{ "control", "getinfo", &getinfo, true }, /* uses wallet if enabled */
|
||||
{ "control", "help", &help, true },
|
||||
{ "control", "stop", &stop, true },
|
||||
|
||||
/* P2P networking */
|
||||
{ "network", "getnetworkinfo", &getnetworkinfo, true },
|
||||
{ "network", "getdeprecationinfo", &getdeprecationinfo, true },
|
||||
{ "network", "addnode", &addnode, true },
|
||||
{ "network", "disconnectnode", &disconnectnode, true },
|
||||
{ "network", "getaddednodeinfo", &getaddednodeinfo, true },
|
||||
{ "network", "getconnectioncount", &getconnectioncount, true },
|
||||
{ "network", "getnettotals", &getnettotals, true },
|
||||
{ "network", "getpeerinfo", &getpeerinfo, true },
|
||||
{ "network", "ping", &ping, true },
|
||||
{ "network", "setban", &setban, true },
|
||||
{ "network", "listbanned", &listbanned, true },
|
||||
{ "network", "clearbanned", &clearbanned, true },
|
||||
|
||||
/* Block chain and UTXO */
|
||||
{ "blockchain", "coinsupply", &coinsupply, true },
|
||||
{ "blockchain", "getblockchaininfo", &getblockchaininfo, true },
|
||||
{ "blockchain", "getbestblockhash", &getbestblockhash, true },
|
||||
{ "blockchain", "getblockcount", &getblockcount, true },
|
||||
{ "blockchain", "getblock", &getblock, true },
|
||||
{ "blockchain", "getblockdeltas", &getblockdeltas, false },
|
||||
{ "blockchain", "getblockhashes", &getblockhashes, true },
|
||||
{ "blockchain", "getblockhash", &getblockhash, true },
|
||||
{ "blockchain", "getblockheader", &getblockheader, true },
|
||||
{ "blockchain", "getchaintips", &getchaintips, true },
|
||||
{ "blockchain", "getdifficulty", &getdifficulty, true },
|
||||
{ "blockchain", "getmempoolinfo", &getmempoolinfo, true },
|
||||
{ "blockchain", "getrawmempool", &getrawmempool, true },
|
||||
{ "blockchain", "gettxout", &gettxout, true },
|
||||
{ "blockchain", "gettxoutproof", &gettxoutproof, true },
|
||||
{ "blockchain", "verifytxoutproof", &verifytxoutproof, true },
|
||||
{ "blockchain", "gettxoutsetinfo", &gettxoutsetinfo, true },
|
||||
{ "blockchain", "verifychain", &verifychain, true },
|
||||
{ "blockchain", "getspentinfo", &getspentinfo, false },
|
||||
//{ "blockchain", "paxprice", &paxprice, true },
|
||||
//{ "blockchain", "paxpending", &paxpending, true },
|
||||
//{ "blockchain", "paxprices", &paxprices, true },
|
||||
{ "blockchain", "notaries", ¬aries, true },
|
||||
//{ "blockchain", "height_MoM", &height_MoM, true },
|
||||
//{ "blockchain", "txMoMproof", &txMoMproof, true },
|
||||
{ "blockchain", "minerids", &minerids, true },
|
||||
{ "blockchain", "kvsearch", &kvsearch, true },
|
||||
{ "blockchain", "kvupdate", &kvupdate, true },
|
||||
|
||||
/* Cross chain utilities */
|
||||
{ "crosschain", "MoMoMdata", &MoMoMdata, true },
|
||||
{ "crosschain", "calc_MoM", &calc_MoM, true },
|
||||
{ "crosschain", "height_MoM", &height_MoM, true },
|
||||
{ "crosschain", "assetchainproof", &assetchainproof, true },
|
||||
{ "crosschain", "crosschainproof", &crosschainproof, true },
|
||||
{ "crosschain", "getNotarisationsForBlock", &getNotarisationsForBlock, true },
|
||||
{ "crosschain", "scanNotarisationsDB", &scanNotarisationsDB, true },
|
||||
{ "crosschain", "migrate_converttoexport", &migrate_converttoexport, true },
|
||||
{ "crosschain", "migrate_createimporttransaction", &migrate_createimporttransaction, true },
|
||||
{ "crosschain", "migrate_completeimporttransaction", &migrate_completeimporttransaction, true },
|
||||
|
||||
/* Mining */
|
||||
{ "mining", "getblocktemplate", &getblocktemplate, true },
|
||||
{ "mining", "getmininginfo", &getmininginfo, true },
|
||||
{ "mining", "getlocalsolps", &getlocalsolps, true },
|
||||
{ "mining", "getnetworksolps", &getnetworksolps, true },
|
||||
{ "mining", "getnetworkhashps", &getnetworkhashps, true },
|
||||
{ "mining", "prioritisetransaction", &prioritisetransaction, true },
|
||||
{ "mining", "submitblock", &submitblock, true },
|
||||
{ "mining", "getblocksubsidy", &getblocksubsidy, true },
|
||||
|
||||
#ifdef ENABLE_MINING
|
||||
/* Coin generation */
|
||||
{ "generating", "getgenerate", &getgenerate, true },
|
||||
{ "generating", "setgenerate", &setgenerate, true },
|
||||
{ "generating", "generate", &generate, true },
|
||||
#endif
|
||||
|
||||
/* Raw transactions */
|
||||
{ "rawtransactions", "createrawtransaction", &createrawtransaction, true },
|
||||
{ "rawtransactions", "decoderawtransaction", &decoderawtransaction, true },
|
||||
{ "rawtransactions", "decodescript", &decodescript, true },
|
||||
{ "rawtransactions", "getrawtransaction", &getrawtransaction, true },
|
||||
{ "rawtransactions", "sendrawtransaction", &sendrawtransaction, false },
|
||||
{ "rawtransactions", "signrawtransaction", &signrawtransaction, false }, /* uses wallet if enabled */
|
||||
#ifdef ENABLE_WALLET
|
||||
{ "rawtransactions", "fundrawtransaction", &fundrawtransaction, false },
|
||||
#endif
|
||||
/* auction */
|
||||
{ "auction", "auctionaddress", &auctionaddress, true },
|
||||
|
||||
/* lotto */
|
||||
{ "lotto", "lottoaddress", &lottoaddress, true },
|
||||
|
||||
/* fsm */
|
||||
{ "FSM", "FSMaddress", &FSMaddress, true },
|
||||
{ "FSM", "FSMcreate", &FSMcreate, true },
|
||||
{ "FSM", "FSMlist", &FSMlist, true },
|
||||
{ "FSM", "FSMinfo", &FSMinfo, true },
|
||||
|
||||
/* rewards */
|
||||
{ "rewards", "rewardslist", &rewardslist, true },
|
||||
{ "rewards", "rewardsinfo", &rewardsinfo, true },
|
||||
{ "rewards", "rewardscreatefunding", &rewardscreatefunding, true },
|
||||
{ "rewards", "rewardsaddfunding", &rewardsaddfunding, true },
|
||||
{ "rewards", "rewardslock", &rewardslock, true },
|
||||
{ "rewards", "rewardsunlock", &rewardsunlock, true },
|
||||
{ "rewards", "rewardsaddress", &rewardsaddress, true },
|
||||
|
||||
/* faucet */
|
||||
{ "faucet", "faucetinfo", &faucetinfo, true },
|
||||
{ "faucet", "faucetfund", &faucetfund, true },
|
||||
{ "faucet", "faucetget", &faucetget, true },
|
||||
{ "faucet", "faucetaddress", &faucetaddress, true },
|
||||
|
||||
/* Heir */
|
||||
{ "heir", "heiraddress", &heiraddress, true },
|
||||
|
||||
/* Channels */
|
||||
{ "channels", "channelsaddress", &channelsaddress, true },
|
||||
{ "channels", "channelsinfo", &channelsinfo, true },
|
||||
{ "channels", "channelsopen", &channelsopen, true },
|
||||
{ "channels", "channelspayment", &channelspayment, true },
|
||||
{ "channels", "channelsclose", &channelsclose, true },
|
||||
{ "channels", "channelsrefund", &channelsrefund, true },
|
||||
|
||||
/* Oracles */
|
||||
{ "oracles", "oraclesaddress", &oraclesaddress, true },
|
||||
{ "oracles", "oracleslist", &oracleslist, true },
|
||||
{ "oracles", "oraclesinfo", &oraclesinfo, true },
|
||||
{ "oracles", "oraclescreate", &oraclescreate, true },
|
||||
{ "oracles", "oraclesregister", &oraclesregister, true },
|
||||
{ "oracles", "oraclessubscribe", &oraclessubscribe, true },
|
||||
{ "oracles", "oraclesdata", &oraclesdata, true },
|
||||
{ "oracles", "oraclessamples", &oraclessamples, true },
|
||||
|
||||
/* Prices */
|
||||
{ "prices", "pricesaddress", &pricesaddress, true },
|
||||
{ "prices", "priceslist", &priceslist, true },
|
||||
{ "prices", "pricesinfo", &pricesinfo, true },
|
||||
{ "prices", "pricescreate", &pricescreate, true },
|
||||
{ "prices", "pricesaddfunding", &pricesaddfunding, true },
|
||||
{ "prices", "pricesbet", &pricesbet, true },
|
||||
{ "prices", "pricesstatus", &pricesstatus, true },
|
||||
{ "prices", "pricesfinish", &pricesfinish, true },
|
||||
|
||||
/* Pegs */
|
||||
{ "pegs", "pegsaddress", &pegsaddress, true },
|
||||
|
||||
/* Triggers */
|
||||
{ "triggers", "triggersaddress", &triggersaddress, true },
|
||||
|
||||
/* Payments */
|
||||
{ "payments", "paymentsaddress", &paymentsaddress, true },
|
||||
|
||||
/* Gateways */
|
||||
{ "gateways", "gatewaysaddress", &gatewaysaddress, true },
|
||||
{ "gateways", "gatewayslist", &gatewayslist, true },
|
||||
{ "gateways", "gatewaysinfo", &gatewaysinfo, true },
|
||||
{ "gateways", "gatewaysbind", &gatewaysbind, true },
|
||||
{ "gateways", "gatewaysdeposit", &gatewaysdeposit, true },
|
||||
{ "gateways", "gatewaysclaim", &gatewaysclaim, true },
|
||||
{ "gateways", "gatewayswithdraw", &gatewayswithdraw, true },
|
||||
{ "gateways", "gatewayspending", &gatewayspending, true },
|
||||
{ "gateways", "gatewaysmultisig", &gatewaysmultisig, true },
|
||||
{ "gateways", "gatewaysmarkdone", &gatewaysmarkdone, true },
|
||||
{ "gateways", "gatewayspartialsign", &gatewayspartialsign, true },
|
||||
|
||||
/* dice */
|
||||
{ "dice", "dicelist", &dicelist, true },
|
||||
{ "dice", "diceinfo", &diceinfo, true },
|
||||
{ "dice", "dicefund", &dicefund, true },
|
||||
{ "dice", "diceaddfunds", &diceaddfunds, true },
|
||||
{ "dice", "dicebet", &dicebet, true },
|
||||
{ "dice", "dicefinish", &dicefinish, true },
|
||||
{ "dice", "dicestatus", &dicestatus, true },
|
||||
{ "dice", "diceaddress", &diceaddress, true },
|
||||
|
||||
/* tokens */
|
||||
{ "tokens", "tokeninfo", &tokeninfo, true },
|
||||
{ "tokens", "tokenlist", &tokenlist, true },
|
||||
{ "tokens", "tokenorders", &tokenorders, true },
|
||||
{ "tokens", "tokenaddress", &tokenaddress, true },
|
||||
{ "tokens", "tokenbalance", &tokenbalance, true },
|
||||
{ "tokens", "tokencreate", &tokencreate, true },
|
||||
{ "tokens", "tokentransfer", &tokentransfer, true },
|
||||
{ "tokens", "tokenbid", &tokenbid, true },
|
||||
{ "tokens", "tokencancelbid", &tokencancelbid, true },
|
||||
{ "tokens", "tokenfillbid", &tokenfillbid, true },
|
||||
{ "tokens", "tokenask", &tokenask, true },
|
||||
//{ "tokens", "tokenswapask", &tokenswapask, true },
|
||||
{ "tokens", "tokencancelask", &tokencancelask, true },
|
||||
{ "tokens", "tokenfillask", &tokenfillask, true },
|
||||
//{ "tokens", "tokenfillswap", &tokenfillswap, true },
|
||||
{ "tokens", "tokenconvert", &tokenconvert, true },
|
||||
|
||||
/* Address index */
|
||||
{ "addressindex", "getaddressmempool", &getaddressmempool, true },
|
||||
{ "addressindex", "getaddressutxos", &getaddressutxos, false },
|
||||
{ "addressindex", "getaddressdeltas", &getaddressdeltas, false },
|
||||
{ "addressindex", "getaddresstxids", &getaddresstxids, false },
|
||||
{ "addressindex", "getaddressbalance", &getaddressbalance, false },
|
||||
{ "addressindex", "getsnapshot", &getsnapshot, false },
|
||||
|
||||
/* Utility functions */
|
||||
{ "util", "createmultisig", &createmultisig, true },
|
||||
{ "util", "validateaddress", &validateaddress, true }, /* uses wallet if enabled */
|
||||
{ "util", "verifymessage", &verifymessage, true },
|
||||
{ "util", "estimatefee", &estimatefee, true },
|
||||
{ "util", "estimatepriority", &estimatepriority, true },
|
||||
{ "util", "z_validateaddress", &z_validateaddress, true }, /* uses wallet if enabled */
|
||||
{ "util", "jumblr_deposit", &jumblr_deposit, true },
|
||||
{ "util", "jumblr_secret", &jumblr_secret, true },
|
||||
{ "util", "jumblr_pause", &jumblr_pause, true },
|
||||
{ "util", "jumblr_resume", &jumblr_resume, true },
|
||||
|
||||
{ "util", "invalidateblock", &invalidateblock, true },
|
||||
{ "util", "reconsiderblock", &reconsiderblock, true },
|
||||
/* Not shown in help */
|
||||
{ "hidden", "setmocktime", &setmocktime, true },
|
||||
#ifdef ENABLE_WALLET
|
||||
{ "wallet", "resendwallettransactions", &resendwallettransactions, true},
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_WALLET
|
||||
/* Wallet */
|
||||
{ "wallet", "addmultisigaddress", &addmultisigaddress, true },
|
||||
{ "wallet", "backupwallet", &backupwallet, true },
|
||||
{ "wallet", "dumpprivkey", &dumpprivkey, true },
|
||||
{ "wallet", "dumpwallet", &dumpwallet, true },
|
||||
{ "wallet", "encryptwallet", &encryptwallet, true },
|
||||
{ "wallet", "getaccountaddress", &getaccountaddress, true },
|
||||
{ "wallet", "getaccount", &getaccount, true },
|
||||
{ "wallet", "getaddressesbyaccount", &getaddressesbyaccount, true },
|
||||
{ "wallet", "getbalance", &getbalance, false },
|
||||
{ "wallet", "getbalance64", &getbalance64, false },
|
||||
{ "wallet", "getnewaddress", &getnewaddress, true },
|
||||
// { "wallet", "getnewaddress64", &getnewaddress64, true },
|
||||
{ "wallet", "getrawchangeaddress", &getrawchangeaddress, true },
|
||||
{ "wallet", "getreceivedbyaccount", &getreceivedbyaccount, false },
|
||||
{ "wallet", "getreceivedbyaddress", &getreceivedbyaddress, false },
|
||||
{ "wallet", "gettransaction", &gettransaction, false },
|
||||
{ "wallet", "getunconfirmedbalance", &getunconfirmedbalance, false },
|
||||
{ "wallet", "getwalletinfo", &getwalletinfo, false },
|
||||
{ "wallet", "importprivkey", &importprivkey, true },
|
||||
{ "wallet", "importwallet", &importwallet, true },
|
||||
{ "wallet", "importaddress", &importaddress, true },
|
||||
{ "wallet", "keypoolrefill", &keypoolrefill, true },
|
||||
{ "wallet", "listaccounts", &listaccounts, false },
|
||||
{ "wallet", "listaddressgroupings", &listaddressgroupings, false },
|
||||
{ "wallet", "listlockunspent", &listlockunspent, false },
|
||||
{ "wallet", "listreceivedbyaccount", &listreceivedbyaccount, false },
|
||||
{ "wallet", "listreceivedbyaddress", &listreceivedbyaddress, false },
|
||||
{ "wallet", "listsinceblock", &listsinceblock, false },
|
||||
{ "wallet", "listtransactions", &listtransactions, false },
|
||||
{ "wallet", "listunspent", &listunspent, false },
|
||||
{ "wallet", "lockunspent", &lockunspent, true },
|
||||
{ "wallet", "move", &movecmd, false },
|
||||
{ "wallet", "sendfrom", &sendfrom, false },
|
||||
{ "wallet", "sendmany", &sendmany, false },
|
||||
{ "wallet", "sendtoaddress", &sendtoaddress, false },
|
||||
{ "wallet", "setaccount", &setaccount, true },
|
||||
{ "wallet", "setpubkey", &setpubkey, true },
|
||||
{ "wallet", "settxfee", &settxfee, true },
|
||||
{ "wallet", "signmessage", &signmessage, true },
|
||||
{ "wallet", "walletlock", &walletlock, true },
|
||||
{ "wallet", "walletpassphrasechange", &walletpassphrasechange, true },
|
||||
{ "wallet", "walletpassphrase", &walletpassphrase, true },
|
||||
{ "wallet", "zcbenchmark", &zc_benchmark, true },
|
||||
{ "wallet", "zcrawkeygen", &zc_raw_keygen, true },
|
||||
{ "wallet", "zcrawjoinsplit", &zc_raw_joinsplit, true },
|
||||
{ "wallet", "zcrawreceive", &zc_raw_receive, true },
|
||||
{ "wallet", "zcsamplejoinsplit", &zc_sample_joinsplit, true },
|
||||
{ "wallet", "z_listreceivedbyaddress",&z_listreceivedbyaddress,false },
|
||||
{ "wallet", "z_getbalance", &z_getbalance, false },
|
||||
{ "wallet", "z_gettotalbalance", &z_gettotalbalance, false },
|
||||
{ "wallet", "z_mergetoaddress", &z_mergetoaddress, false },
|
||||
{ "wallet", "z_sendmany", &z_sendmany, false },
|
||||
{ "wallet", "z_shieldcoinbase", &z_shieldcoinbase, false },
|
||||
{ "wallet", "z_getoperationstatus", &z_getoperationstatus, true },
|
||||
{ "wallet", "z_getoperationresult", &z_getoperationresult, true },
|
||||
{ "wallet", "z_listoperationids", &z_listoperationids, true },
|
||||
{ "wallet", "z_getnewaddress", &z_getnewaddress, true },
|
||||
{ "wallet", "z_listaddresses", &z_listaddresses, true },
|
||||
{ "wallet", "z_exportkey", &z_exportkey, true },
|
||||
{ "wallet", "z_importkey", &z_importkey, true },
|
||||
{ "wallet", "z_exportviewingkey", &z_exportviewingkey, true },
|
||||
{ "wallet", "z_importviewingkey", &z_importviewingkey, true },
|
||||
{ "wallet", "z_exportwallet", &z_exportwallet, true },
|
||||
{ "wallet", "z_importwallet", &z_importwallet, true },
|
||||
|
||||
// TODO: rearrange into another category
|
||||
{ "disclosure", "z_getpaymentdisclosure", &z_getpaymentdisclosure, true },
|
||||
{ "disclosure", "z_validatepaymentdisclosure", &z_validatepaymentdisclosure, true }
|
||||
#endif // ENABLE_WALLET
|
||||
};
|
||||
|
||||
CRPCTable::CRPCTable()
|
||||
{
|
||||
unsigned int vcidx;
|
||||
for (vcidx = 0; vcidx < (sizeof(vRPCCommands) / sizeof(vRPCCommands[0])); vcidx++)
|
||||
{
|
||||
const CRPCCommand *pcmd;
|
||||
|
||||
pcmd = &vRPCCommands[vcidx];
|
||||
mapCommands[pcmd->name] = pcmd;
|
||||
}
|
||||
}
|
||||
|
||||
const CRPCCommand *CRPCTable::operator[](const std::string &name) const
|
||||
{
|
||||
map<string, const CRPCCommand*>::const_iterator it = mapCommands.find(name);
|
||||
if (it == mapCommands.end())
|
||||
return NULL;
|
||||
return (*it).second;
|
||||
}
|
||||
|
||||
bool StartRPC()
|
||||
{
|
||||
LogPrint("rpc", "Starting RPC\n");
|
||||
fRPCRunning = true;
|
||||
g_rpcSignals.Started();
|
||||
|
||||
// Launch one async rpc worker. The ability to launch multiple workers is not recommended at present and thus the option is disabled.
|
||||
getAsyncRPCQueue()->addWorker();
|
||||
/*
|
||||
int n = GetArg("-rpcasyncthreads", 1);
|
||||
if (n<1) {
|
||||
LogPrintf("ERROR: Invalid value %d for -rpcasyncthreads. Must be at least 1.\n", n);
|
||||
strerr = strprintf(_("An error occurred while setting up the Async RPC threads, invalid parameter value of %d (must be at least 1)."), n);
|
||||
uiInterface.ThreadSafeMessageBox(strerr, "", CClientUIInterface::MSG_ERROR);
|
||||
StartShutdown();
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < n; i++)
|
||||
getAsyncRPCQueue()->addWorker();
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
void InterruptRPC()
|
||||
{
|
||||
LogPrint("rpc", "Interrupting RPC\n");
|
||||
// Interrupt e.g. running longpolls
|
||||
fRPCRunning = false;
|
||||
}
|
||||
|
||||
void StopRPC()
|
||||
{
|
||||
LogPrint("rpc", "Stopping RPC\n");
|
||||
deadlineTimers.clear();
|
||||
g_rpcSignals.Stopped();
|
||||
|
||||
// Tells async queue to cancel all operations and shutdown.
|
||||
LogPrintf("%s: waiting for async rpc workers to stop\n", __func__);
|
||||
getAsyncRPCQueue()->closeAndWait();
|
||||
}
|
||||
|
||||
bool IsRPCRunning()
|
||||
{
|
||||
return fRPCRunning;
|
||||
}
|
||||
|
||||
void SetRPCWarmupStatus(const std::string& newStatus)
|
||||
{
|
||||
LOCK(cs_rpcWarmup);
|
||||
rpcWarmupStatus = newStatus;
|
||||
}
|
||||
|
||||
void SetRPCWarmupFinished()
|
||||
{
|
||||
LOCK(cs_rpcWarmup);
|
||||
assert(fRPCInWarmup);
|
||||
fRPCInWarmup = false;
|
||||
}
|
||||
|
||||
bool RPCIsInWarmup(std::string *outStatus)
|
||||
{
|
||||
LOCK(cs_rpcWarmup);
|
||||
if (outStatus)
|
||||
*outStatus = rpcWarmupStatus;
|
||||
return fRPCInWarmup;
|
||||
}
|
||||
|
||||
void JSONRequest::parse(const UniValue& valRequest)
|
||||
{
|
||||
// Parse request
|
||||
if (!valRequest.isObject())
|
||||
throw JSONRPCError(RPC_INVALID_REQUEST, "Invalid Request object");
|
||||
const UniValue& request = valRequest.get_obj();
|
||||
|
||||
// Parse id now so errors from here on will have the id
|
||||
id = find_value(request, "id");
|
||||
|
||||
// Parse method
|
||||
UniValue valMethod = find_value(request, "method");
|
||||
if (valMethod.isNull())
|
||||
throw JSONRPCError(RPC_INVALID_REQUEST, "Missing method");
|
||||
if (!valMethod.isStr())
|
||||
throw JSONRPCError(RPC_INVALID_REQUEST, "Method must be a string");
|
||||
strMethod = valMethod.get_str();
|
||||
if (strMethod != "getblocktemplate")
|
||||
LogPrint("rpc", "ThreadRPCServer method=%s\n", SanitizeString(strMethod));
|
||||
|
||||
// Parse params
|
||||
UniValue valParams = find_value(request, "params");
|
||||
if (valParams.isArray())
|
||||
params = valParams.get_array();
|
||||
else if (valParams.isNull())
|
||||
params = UniValue(UniValue::VARR);
|
||||
else
|
||||
throw JSONRPCError(RPC_INVALID_REQUEST, "Params must be an array");
|
||||
}
|
||||
|
||||
static UniValue JSONRPCExecOne(const UniValue& req)
|
||||
{
|
||||
UniValue rpc_result(UniValue::VOBJ);
|
||||
|
||||
JSONRequest jreq;
|
||||
try {
|
||||
jreq.parse(req);
|
||||
|
||||
UniValue result = tableRPC.execute(jreq.strMethod, jreq.params);
|
||||
rpc_result = JSONRPCReplyObj(result, NullUniValue, jreq.id);
|
||||
}
|
||||
catch (const UniValue& objError)
|
||||
{
|
||||
rpc_result = JSONRPCReplyObj(NullUniValue, objError, jreq.id);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
rpc_result = JSONRPCReplyObj(NullUniValue,
|
||||
JSONRPCError(RPC_PARSE_ERROR, e.what()), jreq.id);
|
||||
}
|
||||
|
||||
return rpc_result;
|
||||
}
|
||||
|
||||
std::string JSONRPCExecBatch(const UniValue& vReq)
|
||||
{
|
||||
UniValue ret(UniValue::VARR);
|
||||
for (size_t reqIdx = 0; reqIdx < vReq.size(); reqIdx++)
|
||||
ret.push_back(JSONRPCExecOne(vReq[reqIdx]));
|
||||
|
||||
return ret.write() + "\n";
|
||||
}
|
||||
|
||||
UniValue CRPCTable::execute(const std::string &strMethod, const UniValue ¶ms) const
|
||||
{
|
||||
// Return immediately if in warmup
|
||||
{
|
||||
LOCK(cs_rpcWarmup);
|
||||
if (fRPCInWarmup)
|
||||
throw JSONRPCError(RPC_IN_WARMUP, rpcWarmupStatus);
|
||||
}
|
||||
|
||||
// Find method
|
||||
const CRPCCommand *pcmd = tableRPC[strMethod];
|
||||
if (!pcmd)
|
||||
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found");
|
||||
|
||||
g_rpcSignals.PreCommand(*pcmd);
|
||||
|
||||
try
|
||||
{
|
||||
// Execute
|
||||
return pcmd->actor(params, false);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
throw JSONRPCError(RPC_MISC_ERROR, e.what());
|
||||
}
|
||||
|
||||
g_rpcSignals.PostCommand(*pcmd);
|
||||
}
|
||||
|
||||
std::string HelpExampleCli(const std::string& methodname, const std::string& args)
|
||||
{
|
||||
return "> komodo-cli " + methodname + " " + args + "\n";
|
||||
}
|
||||
|
||||
std::string HelpExampleRpc(const std::string& methodname, const std::string& args)
|
||||
{
|
||||
return "> curl --user myusername --data-binary '{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", "
|
||||
"\"method\": \"" + methodname + "\", \"params\": [" + args + "] }' -H 'content-type: text/plain;' http://127.0.0.1:7771/\n";
|
||||
}
|
||||
|
||||
void RPCRegisterTimerInterface(RPCTimerInterface *iface)
|
||||
{
|
||||
timerInterfaces.push_back(iface);
|
||||
}
|
||||
|
||||
void RPCUnregisterTimerInterface(RPCTimerInterface *iface)
|
||||
{
|
||||
std::vector<RPCTimerInterface*>::iterator i = std::find(timerInterfaces.begin(), timerInterfaces.end(), iface);
|
||||
assert(i != timerInterfaces.end());
|
||||
timerInterfaces.erase(i);
|
||||
}
|
||||
|
||||
void RPCRunLater(const std::string& name, boost::function<void(void)> func, int64_t nSeconds)
|
||||
{
|
||||
if (timerInterfaces.empty())
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "No timer handler registered for RPC");
|
||||
deadlineTimers.erase(name);
|
||||
RPCTimerInterface* timerInterface = timerInterfaces[0];
|
||||
LogPrint("rpc", "queue run of timer %s in %i seconds (using %s)\n", name, nSeconds, timerInterface->Name());
|
||||
deadlineTimers.insert(std::make_pair(name, boost::shared_ptr<RPCTimerBase>(timerInterface->NewTimer(func, nSeconds*1000))));
|
||||
}
|
||||
|
||||
const CRPCTable tableRPC;
|
||||
|
||||
// Return async rpc queue
|
||||
std::shared_ptr<AsyncRPCQueue> getAsyncRPCQueue()
|
||||
{
|
||||
return AsyncRPCQueue::sharedInstance();
|
||||
}
|
||||
425
src/rpcserver.h
425
src/rpcserver.h
@@ -1,425 +0,0 @@
|
||||
// Copyright (c) 2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2014 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_RPCSERVER_H
|
||||
#define BITCOIN_RPCSERVER_H
|
||||
|
||||
#include "amount.h"
|
||||
#include "rpcprotocol.h"
|
||||
#include "uint256.h"
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
#include <boost/function.hpp>
|
||||
|
||||
#include <univalue.h>
|
||||
|
||||
class AsyncRPCQueue;
|
||||
class CRPCCommand;
|
||||
|
||||
namespace RPCServer
|
||||
{
|
||||
void OnStarted(boost::function<void ()> slot);
|
||||
void OnStopped(boost::function<void ()> slot);
|
||||
void OnPreCommand(boost::function<void (const CRPCCommand&)> slot);
|
||||
void OnPostCommand(boost::function<void (const CRPCCommand&)> slot);
|
||||
}
|
||||
|
||||
class CBlockIndex;
|
||||
class CNetAddr;
|
||||
|
||||
class JSONRequest
|
||||
{
|
||||
public:
|
||||
UniValue id;
|
||||
std::string strMethod;
|
||||
UniValue params;
|
||||
|
||||
JSONRequest() { id = NullUniValue; }
|
||||
void parse(const UniValue& valRequest);
|
||||
};
|
||||
|
||||
/** Query whether RPC is running */
|
||||
bool IsRPCRunning();
|
||||
|
||||
/** Get the async queue*/
|
||||
std::shared_ptr<AsyncRPCQueue> getAsyncRPCQueue();
|
||||
|
||||
|
||||
/**
|
||||
* Set the RPC warmup status. When this is done, all RPC calls will error out
|
||||
* immediately with RPC_IN_WARMUP.
|
||||
*/
|
||||
void SetRPCWarmupStatus(const std::string& newStatus);
|
||||
/* Mark warmup as done. RPC calls will be processed from now on. */
|
||||
void SetRPCWarmupFinished();
|
||||
|
||||
/* returns the current warmup state. */
|
||||
bool RPCIsInWarmup(std::string *statusOut);
|
||||
|
||||
/**
|
||||
* Type-check arguments; throws JSONRPCError if wrong type given. Does not check that
|
||||
* the right number of arguments are passed, just that any passed are the correct type.
|
||||
* Use like: RPCTypeCheck(params, boost::assign::list_of(str_type)(int_type)(obj_type));
|
||||
*/
|
||||
void RPCTypeCheck(const UniValue& params,
|
||||
const std::list<UniValue::VType>& typesExpected, bool fAllowNull=false);
|
||||
|
||||
/*
|
||||
Check for expected keys/value types in an Object.
|
||||
Use like: RPCTypeCheckObj(object, boost::assign::map_list_of("name", str_type)("value", int_type));
|
||||
*/
|
||||
void RPCTypeCheckObj(const UniValue& o,
|
||||
const std::map<std::string, UniValue::VType>& typesExpected, bool fAllowNull=false);
|
||||
|
||||
/** Opaque base class for timers returned by NewTimerFunc.
|
||||
* This provides no methods at the moment, but makes sure that delete
|
||||
* cleans up the whole state.
|
||||
*/
|
||||
class RPCTimerBase
|
||||
{
|
||||
public:
|
||||
virtual ~RPCTimerBase() {}
|
||||
};
|
||||
|
||||
/**
|
||||
* RPC timer "driver".
|
||||
*/
|
||||
class RPCTimerInterface
|
||||
{
|
||||
public:
|
||||
virtual ~RPCTimerInterface() {}
|
||||
/** Implementation name */
|
||||
virtual const char *Name() = 0;
|
||||
/** Factory function for timers.
|
||||
* RPC will call the function to create a timer that will call func in *millis* milliseconds.
|
||||
* @note As the RPC mechanism is backend-neutral, it can use different implementations of timers.
|
||||
* This is needed to cope with the case in which there is no HTTP server, but
|
||||
* only GUI RPC console, and to break the dependency of rpcserver on httprpc.
|
||||
*/
|
||||
virtual RPCTimerBase* NewTimer(boost::function<void(void)>& func, int64_t millis) = 0;
|
||||
};
|
||||
|
||||
/** Register factory function for timers */
|
||||
void RPCRegisterTimerInterface(RPCTimerInterface *iface);
|
||||
/** Unregister factory function for timers */
|
||||
void RPCUnregisterTimerInterface(RPCTimerInterface *iface);
|
||||
|
||||
/**
|
||||
* Run func nSeconds from now.
|
||||
* Overrides previous timer <name> (if any).
|
||||
*/
|
||||
void RPCRunLater(const std::string& name, boost::function<void(void)> func, int64_t nSeconds);
|
||||
|
||||
typedef UniValue(*rpcfn_type)(const UniValue& params, bool fHelp);
|
||||
|
||||
class CRPCCommand
|
||||
{
|
||||
public:
|
||||
std::string category;
|
||||
std::string name;
|
||||
rpcfn_type actor;
|
||||
bool okSafeMode;
|
||||
};
|
||||
|
||||
/**
|
||||
* Bitcoin RPC command dispatcher.
|
||||
*/
|
||||
class CRPCTable
|
||||
{
|
||||
private:
|
||||
std::map<std::string, const CRPCCommand*> mapCommands;
|
||||
public:
|
||||
CRPCTable();
|
||||
const CRPCCommand* operator[](const std::string& name) const;
|
||||
std::string help(const std::string& name) const;
|
||||
|
||||
/**
|
||||
* Execute a method.
|
||||
* @param method Method to execute
|
||||
* @param params UniValue Array of arguments (JSON objects)
|
||||
* @returns Result of the call.
|
||||
* @throws an exception (UniValue) when an error happens.
|
||||
*/
|
||||
UniValue execute(const std::string &method, const UniValue ¶ms) const;
|
||||
};
|
||||
|
||||
extern const CRPCTable tableRPC;
|
||||
|
||||
/**
|
||||
* Utilities: convert hex-encoded Values
|
||||
* (throws error if not hex).
|
||||
*/
|
||||
extern uint256 ParseHashV(const UniValue& v, std::string strName);
|
||||
extern uint256 ParseHashO(const UniValue& o, std::string strKey);
|
||||
extern std::vector<unsigned char> ParseHexV(const UniValue& v, std::string strName);
|
||||
extern std::vector<unsigned char> ParseHexO(const UniValue& o, std::string strKey);
|
||||
|
||||
extern int64_t nWalletUnlockTime;
|
||||
extern CAmount AmountFromValue(const UniValue& value);
|
||||
extern UniValue ValueFromAmount(const CAmount& amount);
|
||||
extern double GetDifficulty(const CBlockIndex* blockindex = NULL);
|
||||
extern double GetNetworkDifficulty(const CBlockIndex* blockindex = NULL);
|
||||
extern std::string HelpRequiringPassphrase();
|
||||
extern std::string HelpExampleCli(const std::string& methodname, const std::string& args);
|
||||
extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args);
|
||||
|
||||
extern void EnsureWalletIsUnlocked();
|
||||
|
||||
extern UniValue getconnectioncount(const UniValue& params, bool fHelp); // in rpcnet.cpp
|
||||
extern UniValue getaddressmempool(const UniValue& params, bool fHelp);
|
||||
extern UniValue getaddressutxos(const UniValue& params, bool fHelp);
|
||||
extern UniValue getaddressdeltas(const UniValue& params, bool fHelp);
|
||||
extern UniValue getaddresstxids(const UniValue& params, bool fHelp);
|
||||
extern UniValue getsnapshot(const UniValue& params, bool fHelp);
|
||||
extern UniValue getaddressbalance(const UniValue& params, bool fHelp);
|
||||
extern UniValue getpeerinfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue ping(const UniValue& params, bool fHelp);
|
||||
extern UniValue addnode(const UniValue& params, bool fHelp);
|
||||
extern UniValue disconnectnode(const UniValue& params, bool fHelp);
|
||||
extern UniValue getaddednodeinfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue getnettotals(const UniValue& params, bool fHelp);
|
||||
extern UniValue setban(const UniValue& params, bool fHelp);
|
||||
extern UniValue listbanned(const UniValue& params, bool fHelp);
|
||||
extern UniValue clearbanned(const UniValue& params, bool fHelp);
|
||||
|
||||
extern UniValue dumpprivkey(const UniValue& params, bool fHelp); // in rpcdump.cpp
|
||||
extern UniValue importprivkey(const UniValue& params, bool fHelp);
|
||||
extern UniValue importaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue dumpwallet(const UniValue& params, bool fHelp);
|
||||
extern UniValue importwallet(const UniValue& params, bool fHelp);
|
||||
|
||||
extern UniValue getgenerate(const UniValue& params, bool fHelp); // in rpcmining.cpp
|
||||
extern UniValue setgenerate(const UniValue& params, bool fHelp);
|
||||
extern UniValue generate(const UniValue& params, bool fHelp);
|
||||
extern UniValue getlocalsolps(const UniValue& params, bool fHelp);
|
||||
extern UniValue getnetworksolps(const UniValue& params, bool fHelp);
|
||||
extern UniValue getnetworkhashps(const UniValue& params, bool fHelp);
|
||||
extern UniValue getmininginfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue prioritisetransaction(const UniValue& params, bool fHelp);
|
||||
extern UniValue getblocktemplate(const UniValue& params, bool fHelp);
|
||||
extern UniValue submitblock(const UniValue& params, bool fHelp);
|
||||
extern UniValue estimatefee(const UniValue& params, bool fHelp);
|
||||
extern UniValue estimatepriority(const UniValue& params, bool fHelp);
|
||||
extern UniValue coinsupply(const UniValue& params, bool fHelp);
|
||||
extern UniValue tokeninfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue tokenlist(const UniValue& params, bool fHelp);
|
||||
extern UniValue tokenorders(const UniValue& params, bool fHelp);
|
||||
extern UniValue tokenbalance(const UniValue& params, bool fHelp);
|
||||
extern UniValue tokenaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue tokencreate(const UniValue& params, bool fHelp);
|
||||
extern UniValue tokentransfer(const UniValue& params, bool fHelp);
|
||||
extern UniValue tokenbid(const UniValue& params, bool fHelp);
|
||||
extern UniValue tokencancelbid(const UniValue& params, bool fHelp);
|
||||
extern UniValue tokenfillbid(const UniValue& params, bool fHelp);
|
||||
extern UniValue tokenask(const UniValue& params, bool fHelp);
|
||||
extern UniValue tokencancelask(const UniValue& params, bool fHelp);
|
||||
extern UniValue tokenfillask(const UniValue& params, bool fHelp);
|
||||
extern UniValue tokenconvert(const UniValue& params, bool fHelp);
|
||||
extern UniValue heiraddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue channelsaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue oraclesaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue oracleslist(const UniValue& params, bool fHelp);
|
||||
extern UniValue oraclesinfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue oraclescreate(const UniValue& params, bool fHelp);
|
||||
extern UniValue oraclesregister(const UniValue& params, bool fHelp);
|
||||
extern UniValue oraclessubscribe(const UniValue& params, bool fHelp);
|
||||
extern UniValue oraclesdata(const UniValue& params, bool fHelp);
|
||||
extern UniValue oraclessamples(const UniValue& params, bool fHelp);
|
||||
extern UniValue pricesaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue priceslist(const UniValue& params, bool fHelp);
|
||||
extern UniValue pricesinfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue pricescreate(const UniValue& params, bool fHelp);
|
||||
extern UniValue pricesaddfunding(const UniValue& params, bool fHelp);
|
||||
extern UniValue pricesbet(const UniValue& params, bool fHelp);
|
||||
extern UniValue pricesstatus(const UniValue& params, bool fHelp);
|
||||
extern UniValue pricesfinish(const UniValue& params, bool fHelp);
|
||||
extern UniValue pegsaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue triggersaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue paymentsaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue gatewaysaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue gatewayslist(const UniValue& params, bool fHelp);
|
||||
extern UniValue gatewaysinfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue gatewaysbind(const UniValue& params, bool fHelp);
|
||||
extern UniValue gatewaysdeposit(const UniValue& params, bool fHelp);
|
||||
extern UniValue gatewaysclaim(const UniValue& params, bool fHelp);
|
||||
extern UniValue gatewayswithdraw(const UniValue& params, bool fHelp);
|
||||
extern UniValue gatewayspending(const UniValue& params, bool fHelp);
|
||||
extern UniValue gatewaysmarkdone(const UniValue& params, bool fHelp);
|
||||
extern UniValue gatewaysmultisig(const UniValue& params, bool fHelp);
|
||||
extern UniValue gatewayspartialsign(const UniValue& params, bool fHelp);
|
||||
extern UniValue channelsinfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue channelsopen(const UniValue& params, bool fHelp);
|
||||
extern UniValue channelspayment(const UniValue& params, bool fHelp);
|
||||
extern UniValue channelsclose(const UniValue& params, bool fHelp);
|
||||
extern UniValue channelsrefund(const UniValue& params, bool fHelp);
|
||||
|
||||
//extern UniValue tokenswapask(const UniValue& params, bool fHelp);
|
||||
//extern UniValue tokenfillswap(const UniValue& params, bool fHelp);
|
||||
extern UniValue faucetfund(const UniValue& params, bool fHelp);
|
||||
extern UniValue faucetget(const UniValue& params, bool fHelp);
|
||||
extern UniValue faucetaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue faucetinfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue rewardsinfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue rewardslist(const UniValue& params, bool fHelp);
|
||||
extern UniValue rewardsaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue rewardscreatefunding(const UniValue& params, bool fHelp);
|
||||
extern UniValue rewardsaddfunding(const UniValue& params, bool fHelp);
|
||||
extern UniValue rewardslock(const UniValue& params, bool fHelp);
|
||||
extern UniValue rewardsunlock(const UniValue& params, bool fHelp);
|
||||
extern UniValue diceaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue dicefund(const UniValue& params, bool fHelp);
|
||||
extern UniValue dicelist(const UniValue& params, bool fHelp);
|
||||
extern UniValue diceinfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue diceaddfunds(const UniValue& params, bool fHelp);
|
||||
extern UniValue dicebet(const UniValue& params, bool fHelp);
|
||||
extern UniValue dicefinish(const UniValue& params, bool fHelp);
|
||||
extern UniValue dicestatus(const UniValue& params, bool fHelp);
|
||||
extern UniValue lottoaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue FSMaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue FSMcreate(const UniValue& params, bool fHelp);
|
||||
extern UniValue FSMlist(const UniValue& params, bool fHelp);
|
||||
extern UniValue FSMinfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue auctionaddress(const UniValue& params, bool fHelp);
|
||||
|
||||
extern UniValue getnewaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp
|
||||
//extern UniValue getnewaddress64(const UniValue& params, bool fHelp); // in rpcwallet.cpp
|
||||
extern UniValue getaccountaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue getrawchangeaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue setaccount(const UniValue& params, bool fHelp);
|
||||
extern UniValue getaccount(const UniValue& params, bool fHelp);
|
||||
extern UniValue getaddressesbyaccount(const UniValue& params, bool fHelp);
|
||||
extern UniValue sendtoaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue signmessage(const UniValue& params, bool fHelp);
|
||||
extern UniValue verifymessage(const UniValue& params, bool fHelp);
|
||||
extern UniValue getreceivedbyaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue getreceivedbyaccount(const UniValue& params, bool fHelp);
|
||||
extern UniValue getbalance(const UniValue& params, bool fHelp);
|
||||
extern UniValue getbalance64(const UniValue& params, bool fHelp);
|
||||
extern UniValue getunconfirmedbalance(const UniValue& params, bool fHelp);
|
||||
extern UniValue movecmd(const UniValue& params, bool fHelp);
|
||||
extern UniValue sendfrom(const UniValue& params, bool fHelp);
|
||||
extern UniValue sendmany(const UniValue& params, bool fHelp);
|
||||
extern UniValue addmultisigaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue createmultisig(const UniValue& params, bool fHelp);
|
||||
extern UniValue listreceivedbyaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue listreceivedbyaccount(const UniValue& params, bool fHelp);
|
||||
extern UniValue listtransactions(const UniValue& params, bool fHelp);
|
||||
extern UniValue listaddressgroupings(const UniValue& params, bool fHelp);
|
||||
extern UniValue listaccounts(const UniValue& params, bool fHelp);
|
||||
extern UniValue listsinceblock(const UniValue& params, bool fHelp);
|
||||
extern UniValue gettransaction(const UniValue& params, bool fHelp);
|
||||
extern UniValue backupwallet(const UniValue& params, bool fHelp);
|
||||
extern UniValue keypoolrefill(const UniValue& params, bool fHelp);
|
||||
extern UniValue walletpassphrase(const UniValue& params, bool fHelp);
|
||||
extern UniValue walletpassphrasechange(const UniValue& params, bool fHelp);
|
||||
extern UniValue walletlock(const UniValue& params, bool fHelp);
|
||||
extern UniValue encryptwallet(const UniValue& params, bool fHelp);
|
||||
extern UniValue validateaddress(const UniValue& params, bool fHelp);
|
||||
extern UniValue getinfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue setpubkey(const UniValue& params, bool fHelp);
|
||||
extern UniValue getwalletinfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue getblockchaininfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue getnetworkinfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue getdeprecationinfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue setmocktime(const UniValue& params, bool fHelp);
|
||||
extern UniValue resendwallettransactions(const UniValue& params, bool fHelp);
|
||||
extern UniValue zc_benchmark(const UniValue& params, bool fHelp);
|
||||
extern UniValue zc_raw_keygen(const UniValue& params, bool fHelp);
|
||||
extern UniValue zc_raw_joinsplit(const UniValue& params, bool fHelp);
|
||||
extern UniValue zc_raw_receive(const UniValue& params, bool fHelp);
|
||||
extern UniValue zc_sample_joinsplit(const UniValue& params, bool fHelp);
|
||||
|
||||
extern UniValue jumblr_deposit(const UniValue& params, bool fHelp);
|
||||
extern UniValue jumblr_secret(const UniValue& params, bool fHelp);
|
||||
extern UniValue jumblr_pause(const UniValue& params, bool fHelp);
|
||||
extern UniValue jumblr_resume(const UniValue& params, bool fHelp);
|
||||
|
||||
extern UniValue getrawtransaction(const UniValue& params, bool fHelp); // in rcprawtransaction.cpp
|
||||
extern UniValue listunspent(const UniValue& params, bool fHelp);
|
||||
extern UniValue lockunspent(const UniValue& params, bool fHelp);
|
||||
extern UniValue listlockunspent(const UniValue& params, bool fHelp);
|
||||
extern UniValue createrawtransaction(const UniValue& params, bool fHelp);
|
||||
extern UniValue decoderawtransaction(const UniValue& params, bool fHelp);
|
||||
extern UniValue decodescript(const UniValue& params, bool fHelp);
|
||||
extern UniValue fundrawtransaction(const UniValue& params, bool fHelp);
|
||||
extern UniValue signrawtransaction(const UniValue& params, bool fHelp);
|
||||
extern UniValue sendrawtransaction(const UniValue& params, bool fHelp);
|
||||
extern UniValue gettxoutproof(const UniValue& params, bool fHelp);
|
||||
extern UniValue verifytxoutproof(const UniValue& params, bool fHelp);
|
||||
|
||||
extern UniValue getblockcount(const UniValue& params, bool fHelp); // in rpcblockchain.cpp
|
||||
extern UniValue getbestblockhash(const UniValue& params, bool fHelp);
|
||||
extern UniValue getdifficulty(const UniValue& params, bool fHelp);
|
||||
extern UniValue settxfee(const UniValue& params, bool fHelp);
|
||||
extern UniValue getmempoolinfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue getrawmempool(const UniValue& params, bool fHelp);
|
||||
extern UniValue getblockhashes(const UniValue& params, bool fHelp);
|
||||
extern UniValue getblockdeltas(const UniValue& params, bool fHelp);
|
||||
extern UniValue getblockhash(const UniValue& params, bool fHelp);
|
||||
extern UniValue getblockheader(const UniValue& params, bool fHelp);
|
||||
extern UniValue getblock(const UniValue& params, bool fHelp);
|
||||
extern UniValue gettxoutsetinfo(const UniValue& params, bool fHelp);
|
||||
extern UniValue gettxout(const UniValue& params, bool fHelp);
|
||||
extern UniValue verifychain(const UniValue& params, bool fHelp);
|
||||
extern UniValue getchaintips(const UniValue& params, bool fHelp);
|
||||
extern UniValue invalidateblock(const UniValue& params, bool fHelp);
|
||||
extern UniValue reconsiderblock(const UniValue& params, bool fHelp);
|
||||
extern UniValue getspentinfo(const UniValue& params, bool fHelp);
|
||||
|
||||
extern UniValue getblocksubsidy(const UniValue& params, bool fHelp);
|
||||
|
||||
extern UniValue z_exportkey(const UniValue& params, bool fHelp); // in rpcdump.cpp
|
||||
extern UniValue z_importkey(const UniValue& params, bool fHelp); // in rpcdump.cpp
|
||||
extern UniValue z_exportviewingkey(const UniValue& params, bool fHelp); // in rpcdump.cpp
|
||||
extern UniValue z_importviewingkey(const UniValue& params, bool fHelp); // in rpcdump.cpp
|
||||
extern UniValue z_getnewaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp
|
||||
extern UniValue z_listaddresses(const UniValue& params, bool fHelp); // in rpcwallet.cpp
|
||||
extern UniValue z_exportwallet(const UniValue& params, bool fHelp); // in rpcdump.cpp
|
||||
extern UniValue z_importwallet(const UniValue& params, bool fHelp); // in rpcdump.cpp
|
||||
extern UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp
|
||||
extern UniValue z_getbalance(const UniValue& params, bool fHelp); // in rpcwallet.cpp
|
||||
extern UniValue z_gettotalbalance(const UniValue& params, bool fHelp); // in rpcwallet.cpp
|
||||
extern UniValue z_mergetoaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp
|
||||
extern UniValue z_sendmany(const UniValue& params, bool fHelp); // in rpcwallet.cpp
|
||||
extern UniValue z_shieldcoinbase(const UniValue& params, bool fHelp); // in rpcwallet.cpp
|
||||
extern UniValue z_getoperationstatus(const UniValue& params, bool fHelp); // in rpcwallet.cpp
|
||||
extern UniValue z_getoperationresult(const UniValue& params, bool fHelp); // in rpcwallet.cpp
|
||||
extern UniValue z_listoperationids(const UniValue& params, bool fHelp); // in rpcwallet.cpp
|
||||
extern UniValue z_validateaddress(const UniValue& params, bool fHelp); // in rpcmisc.cpp
|
||||
extern UniValue z_getpaymentdisclosure(const UniValue& params, bool fHelp); // in rpcdisclosure.cpp
|
||||
extern UniValue z_validatepaymentdisclosure(const UniValue ¶ms, bool fHelp); // in rpcdisclosure.cpp
|
||||
|
||||
extern UniValue MoMoMdata(const UniValue& params, bool fHelp);
|
||||
extern UniValue calc_MoM(const UniValue& params, bool fHelp);
|
||||
extern UniValue height_MoM(const UniValue& params, bool fHelp);
|
||||
extern UniValue assetchainproof(const UniValue& params, bool fHelp);
|
||||
extern UniValue crosschainproof(const UniValue& params, bool fHelp);
|
||||
extern UniValue getNotarisationsForBlock(const UniValue& params, bool fHelp);
|
||||
extern UniValue scanNotarisationsDB(const UniValue& params, bool fHelp);
|
||||
extern UniValue migrate_converttoexport(const UniValue& params, bool fHelp);
|
||||
extern UniValue migrate_createimporttransaction(const UniValue& params, bool fHelp);
|
||||
extern UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp);
|
||||
|
||||
extern UniValue notaries(const UniValue& params, bool fHelp);
|
||||
extern UniValue minerids(const UniValue& params, bool fHelp);
|
||||
extern UniValue kvsearch(const UniValue& params, bool fHelp);
|
||||
extern UniValue kvupdate(const UniValue& params, bool fHelp);
|
||||
extern UniValue paxprice(const UniValue& params, bool fHelp);
|
||||
extern UniValue paxpending(const UniValue& params, bool fHelp);
|
||||
extern UniValue paxprices(const UniValue& params, bool fHelp);
|
||||
extern UniValue paxdeposit(const UniValue& params, bool fHelp);
|
||||
extern UniValue paxwithdraw(const UniValue& params, bool fHelp);
|
||||
|
||||
bool StartRPC();
|
||||
void InterruptRPC();
|
||||
void StopRPC();
|
||||
std::string JSONRPCExecBatch(const UniValue& vReq);
|
||||
|
||||
#endif // BITCOIN_RPCSERVER_H
|
||||
Reference in New Issue
Block a user