Fabcoin Core  0.16.2
P2P Digital Currency
token.cpp
Go to the documentation of this file.
1 #include <token.h>
2 #include <execrpccommand.h>
3 #include <contractabi.h>
4 #include <validation.h>
5 #include <utilmoneystr.h>
6 #include <base58.h>
7 #include <utilstrencodings.h>
8 #include <eventlog.h>
9 #include <libethcore/ABI.h>
10 
11 namespace Token_NS
12 {
13 static const std::string TOKEN_ABI = "[{\"constant\":true,\"inputs\":[],\"name\":\"name\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"approve\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"totalSupply\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_from\",\"type\":\"address\"},{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transferFrom\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"decimals\",\"outputs\":[{\"name\":\"\",\"type\":\"uint8\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"burn\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"address\"}],\"name\":\"balanceOf\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_from\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"burnFrom\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"symbol\",\"outputs\":[{\"name\":\"\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_to\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"}],\"name\":\"transfer\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"_spender\",\"type\":\"address\"},{\"name\":\"_value\",\"type\":\"uint256\"},{\"name\":\"_extraData\",\"type\":\"bytes\"}],\"name\":\"approveAndCall\",\"outputs\":[{\"name\":\"success\",\"type\":\"bool\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"address\"},{\"name\":\"\",\"type\":\"address\"}],\"name\":\"allowance\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialSupply\",\"type\":\"uint256\"},{\"name\":\"tokenName\",\"type\":\"string\"},{\"name\":\"decimalUnits\",\"type\":\"uint8\"},{\"name\":\"tokenSymbol\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"from\",\"type\":\"address\"},{\"indexed\":true,\"name\":\"to\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Transfer\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"name\":\"from\",\"type\":\"address\"},{\"indexed\":false,\"name\":\"value\",\"type\":\"uint256\"}],\"name\":\"Burn\",\"type\":\"event\"}]";
14 
15 static const QString PRC_CALL = "callcontract";
16 static const QString PRC_SENDTO = "sendtocontract";
17 static const QString PARAM_ADDRESS = "address";
18 static const QString PARAM_DATAHEX = "datahex";
19 static const QString PARAM_AMOUNT = "amount";
20 static const QString PARAM_GASLIMIT = "gaslimit";
21 static const QString PARAM_GASPRICE = "gasprice";
22 static const QString PARAM_SENDER = "sender";
23 static const QString PARAM_BROADCAST = "broadcast";
24 static const QString PARAM_CHANGE_TO_SENDER = "changeToSender";
25 
26 }
27 using namespace Token_NS;
28 
29 struct TokenData
30 {
31  QMap<QString, QString> lstParams;
32  std::string address;
37  int funcName;
42  int funcBurn;
50  int evtBurn;
51 
52  std::string txid;
53 
55  call(0),
56  send(0),
57  ABI(0),
58  funcName(-1),
59  funcApprove(-1),
60  funcTotalSupply(-1),
61  funcTransferFrom(-1),
62  funcDecimals(-1),
63  funcBurn(-1),
64  funcBalanceOf(-1),
65  funcBurnFrom(-1),
66  funcSymbol(-1),
67  funcTransfer(-1),
68  funcApproveAndCall(-1),
69  funcAllowance(-1),
70  evtTransfer(-1),
71  evtBurn(-1)
72  {}
73 };
74 
75 bool ToHash160(const std::string& strFabTokenAddress, std::string& strHash160)
76 {
77  CFabcoinAddress fabTokenAddress(strFabTokenAddress);
78  if(fabTokenAddress.IsValid()){
79  CKeyID keyid;
80  fabTokenAddress.GetKeyID(keyid);
81  strHash160 = HexStr(valtype(keyid.begin(),keyid.end()));
82  }else{
83  return false;
84  }
85  return true;
86 }
87 
88 bool ToFabTokenAddress(const std::string& strHash160, std::string& strFabTokenAddress)
89 {
90  uint160 key(ParseHex(strHash160.c_str()));
91  CKeyID keyid(key);
92  CFabcoinAddress fabTokenAddress;
93  fabTokenAddress.Set(keyid);
94  if(fabTokenAddress.IsValid()){
95  strFabTokenAddress = fabTokenAddress.ToString();
96  return true;
97  }
98  return false;
99 }
100 
102  d(0)
103 {
104  d = new TokenData();
105  clear();
106 
107  // Create new call command line interface
108  QStringList lstMandatory;
109  lstMandatory.append(PARAM_ADDRESS);
110  lstMandatory.append(PARAM_DATAHEX);
111  QStringList lstOptional;
112  lstOptional.append(PARAM_SENDER);
113  d->call = new ExecRPCCommand(PRC_CALL, lstMandatory, lstOptional, QMap<QString, QString>());
114 
115  // Create new send command line interface
116  lstMandatory.clear();
117  lstMandatory.append(PARAM_ADDRESS);
118  lstMandatory.append(PARAM_DATAHEX);
119  lstOptional.clear();
120  lstOptional.append(PARAM_AMOUNT);
121  lstOptional.append(PARAM_GASLIMIT);
122  lstOptional.append(PARAM_GASPRICE);
123  lstOptional.append(PARAM_SENDER);
124  lstOptional.append(PARAM_BROADCAST);
125  lstOptional.append(PARAM_CHANGE_TO_SENDER);
126  d->send = new ExecRPCCommand(PRC_SENDTO, lstMandatory, lstOptional, QMap<QString, QString>());
127 
128  // Create new event log interface
129  d->eventLog = new EventLog();
130 
131  // Compute functions indexes
132  d->ABI = new ContractABI();
133  if(d->ABI->loads(TOKEN_ABI))
134  {
135  for(size_t i = 0; i < d->ABI->functions.size(); i++)
136  {
137  FunctionABI func = d->ABI->functions[i];
138  if(func.name == "name")
139  {
140  d->funcName = i;
141  }
142  else if(func.name == "approve")
143  {
144  d->funcApprove = i;
145  }
146  else if(func.name == "totalSupply")
147  {
148  d->funcTotalSupply = i;
149  }
150  else if(func.name == "transferFrom")
151  {
152  d->funcTransferFrom = i;
153  }
154  else if(func.name == "decimals")
155  {
156  d->funcDecimals = i;
157  }
158  else if(func.name == "burn")
159  {
160  d->funcBurn = i;
161  }
162  else if(func.name == "balanceOf")
163  {
164  d->funcBalanceOf = i;
165  }
166  else if(func.name == "burnFrom")
167  {
168  d->funcBurnFrom = i;
169  }
170  else if(func.name == "symbol")
171  {
172  d->funcSymbol = i;
173  }
174  else if(func.name == "transfer")
175  {
176  d->funcTransfer = i;
177  }
178  else if(func.name == "approveAndCall")
179  {
180  d->funcApproveAndCall = i;
181  }
182  else if(func.name == "allowance")
183  {
184  d->funcAllowance = i;
185  }
186  else if(func.name == "Transfer")
187  {
188  d->evtTransfer = i;
189  }
190  else if(func.name == "Burn")
191  {
192  d->evtBurn = i;
193  }
194  }
195  }
196 }
197 
199 {
200  if(d->call)
201  delete d->call;
202  d->call = 0;
203 
204  if(d->send)
205  delete d->send;
206  d->send = 0;
207 
208  if(d->ABI)
209  delete d->ABI;
210  d->ABI = 0;
211 
212  if(d)
213  delete d;
214  d = 0;
215 }
216 
217 void Token::setAddress(const std::string &address)
218 {
219  d->lstParams[PARAM_ADDRESS] = QString::fromStdString(address);
220 }
221 
222 void Token::setDataHex(const std::string &datahex)
223 {
224  d->lstParams[PARAM_DATAHEX] = QString::fromStdString(datahex);
225 }
226 
227 void Token::setAmount(const std::string &amount)
228 {
229  d->lstParams[PARAM_AMOUNT] = QString::fromStdString(amount);
230 }
231 
232 void Token::setGasLimit(const std::string &gaslimit)
233 {
234  d->lstParams[PARAM_GASLIMIT] = QString::fromStdString(gaslimit);
235 }
236 
237 void Token::setGasPrice(const std::string &gasPrice)
238 {
239  d->lstParams[PARAM_GASPRICE] = QString::fromStdString(gasPrice);
240 }
241 
242 void Token::setSender(const std::string &sender)
243 {
244  d->lstParams[PARAM_SENDER] = QString::fromStdString(sender);
245 }
246 
248 {
249  d->lstParams.clear();
250 
251  setAmount("0");
252  setGasPrice(FormatMoney(DEFAULT_GAS_PRICE));
253  setGasLimit(std::to_string(DEFAULT_GAS_LIMIT_OP_SEND));
254 
255  d->lstParams[PARAM_BROADCAST] = "true";
256  d->lstParams[PARAM_CHANGE_TO_SENDER] = "true";
257 }
258 
259 std::string Token::getTxId()
260 {
261  return d->txid;
262 }
263 
264 bool Token::name(std::string &result, bool sendTo)
265 {
266  std::vector<std::string> input;
267  std::vector<std::string> output;
268  if(!exec(input, d->funcName, output, sendTo))
269  return false;
270 
271  if(!sendTo)
272  {
273  if(output.size() == 0)
274  return false;
275  else
276  result = output[0];
277  }
278 
279  return true;
280 }
281 
282 bool Token::approve(const std::string &_spender, const std::string &_value, bool &success, bool sendTo)
283 {
284  std::vector<std::string> input;
285  input.push_back(_spender);
286  input.push_back(_value);
287  std::vector<std::string> output;
288 
289  if(!exec(input, d->funcApprove, output, sendTo))
290  return false;
291 
292  if(!sendTo)
293  {
294  if(output.size() == 0)
295  return false;
296  else
297  success = output[0] == "true";
298  }
299 
300  return true;
301 }
302 
303 bool Token::totalSupply(std::string &result, bool sendTo)
304 {
305  std::vector<std::string> input;
306  std::vector<std::string> output;
307  if(!exec(input, d->funcTotalSupply, output, sendTo))
308  return false;
309 
310  if(!sendTo)
311  {
312  if(output.size() == 0)
313  return false;
314  else
315  result = output[0];
316  }
317 
318  return true;
319 }
320 
321 bool Token::transferFrom(const std::string &_from, const std::string &_to, const std::string &_value, bool &success, bool sendTo)
322 {
323  std::vector<std::string> input;
324  input.push_back(_from);
325  input.push_back(_to);
326  input.push_back(_value);
327  std::vector<std::string> output;
328 
329  if(!exec(input, d->funcTransferFrom, output, sendTo))
330  return false;
331 
332  if(!sendTo)
333  {
334  if(output.size() == 0)
335  return false;
336  else
337  success = output[0] == "true";
338  }
339 
340  return true;
341 }
342 
343 bool Token::decimals(std::string &result, bool sendTo)
344 {
345  std::vector<std::string> input;
346  std::vector<std::string> output;
347  if(!exec(input, d->funcDecimals, output, sendTo))
348  return false;
349 
350  if(!sendTo)
351  {
352  if(output.size() == 0)
353  return false;
354  else
355  result = output[0];
356  }
357 
358  return true;
359 }
360 
361 bool Token::burn(const std::string &_value, bool &success, bool sendTo)
362 {
363  std::vector<std::string> input;
364  input.push_back(_value);
365  std::vector<std::string> output;
366 
367  if(!exec(input, d->funcBurn, output, sendTo))
368  return false;
369 
370  if(!sendTo)
371  {
372  if(output.size() == 0)
373  return false;
374  else
375  success = output[0] == "true";
376  }
377 
378  return true;
379 }
380 
381 bool Token::balanceOf(std::string &result, bool sendTo)
382 {
383  std::string spender = d->lstParams[PARAM_SENDER].toStdString();
384  if(!ToHash160(spender, spender))
385  {
386  return false;
387  }
388 
389  return balanceOf(spender, result, sendTo);
390 }
391 
392 bool Token::balanceOf(const std::string &spender, std::string &result, bool sendTo)
393 {
394  std::vector<std::string> input;
395  input.push_back(spender);
396  std::vector<std::string> output;
397 
398  if(!exec(input, d->funcBalanceOf, output, sendTo))
399  return false;
400 
401  if(!sendTo)
402  {
403  if(output.size() == 0)
404  return false;
405  else
406  result = output[0];
407  }
408 
409  return true;
410 }
411 
412 bool Token::burnFrom(const std::string &_from, const std::string &_value, bool &success, bool sendTo)
413 {
414  std::vector<std::string> input;
415  input.push_back(_from);
416  input.push_back(_value);
417  std::vector<std::string> output;
418 
419  if(!exec(input, d->funcBurnFrom, output, sendTo))
420  return false;
421 
422  if(!sendTo)
423  {
424  if(output.size() == 0)
425  return false;
426  else
427  success = output[0] == "true";
428  }
429 
430  return true;
431 }
432 
433 bool Token::symbol(std::string &result, bool sendTo)
434 {
435  std::vector<std::string> input;
436  std::vector<std::string> output;
437  if(!exec(input, d->funcSymbol, output, sendTo))
438  return false;
439 
440  if(!sendTo)
441  {
442  if(output.size() == 0)
443  return false;
444  else
445  result = output[0];
446  }
447 
448  return true;
449 }
450 
451 bool Token::transfer(const std::string &_to, const std::string &_value, bool sendTo)
452 {
453  std::string to = _to;
454  if(!ToHash160(to, to))
455  {
456  return false;
457  }
458 
459  std::vector<std::string> input;
460  input.push_back(to);
461  input.push_back(_value);
462  std::vector<std::string> output;
463 
464  return exec(input, d->funcTransfer, output, sendTo);
465 }
466 
467 bool Token::approveAndCall(const std::string &_spender, const std::string &_value, const std::string &_extraData, bool &success, bool sendTo)
468 {
469  std::vector<std::string> input;
470  input.push_back(_spender);
471  input.push_back(_value);
472  input.push_back(_extraData);
473  std::vector<std::string> output;
474 
475  if(!exec(input, d->funcApproveAndCall, output, sendTo))
476  return false;
477 
478  if(!sendTo)
479  {
480  if(output.size() == 0)
481  return false;
482  else
483  success = output[0] == "true";
484  }
485 
486  return true;
487 }
488 
489 bool Token::allowance(const std::string &_from, const std::string &_to, std::string &result, bool sendTo)
490 {
491  std::vector<std::string> input;
492  input.push_back(_from);
493  input.push_back(_to);
494  std::vector<std::string> output;
495 
496  if(!exec(input, d->funcAllowance, output, sendTo))
497  return false;
498 
499  if(!sendTo)
500  {
501  if(output.size() == 0)
502  return false;
503  else
504  result = output[0];
505  }
506 
507  return true;
508 }
509 
510 bool Token::transferEvents(std::vector<TokenEvent> &tokenEvents, int64_t fromBlock, int64_t toBlock)
511 {
512  return execEvents(fromBlock, toBlock, d->evtTransfer, tokenEvents);
513 }
514 
515 bool Token::burnEvents(std::vector<TokenEvent> &tokenEvents, int64_t fromBlock, int64_t toBlock)
516 {
517  return execEvents(fromBlock, toBlock, d->evtBurn, tokenEvents);
518 }
519 
520 bool Token::exec(const std::vector<std::string> &input, int func, std::vector<std::string> &output, bool sendTo)
521 {
522  // Convert the input data into hex encoded binary data
523  d->txid = "";
524  if(func == -1)
525  return false;
526  std::string strData;
527  FunctionABI function = d->ABI->functions[func];
528  std::vector<std::vector<std::string>> values;
529  for(size_t i = 0; i < input.size(); i++)
530  {
531  std::vector<std::string> param;
532  param.push_back(input[i]);
533  values.push_back(param);
534  }
535  std::vector<ParameterABI::ErrorType> errors;
536  if(!function.abiIn(values, strData, errors))
537  return false;
538  setDataHex(strData);
539 
540  // Execute the command and get the result
541  ExecRPCCommand* cmd = sendTo ? d->send : d->call;
542  QVariant result;
543  QString resultJson;
544  QString errorMessage;
545  if(!cmd->exec(d->lstParams, result, resultJson, errorMessage))
546  return false;
547 
548  // Get the result from calling function
549  if(!sendTo)
550  {
551  QVariantMap variantMap = result.toMap();
552  QVariantMap executionResultMap = variantMap.value("executionResult").toMap();
553  std::string rawData = executionResultMap.value("output").toString().toStdString();
554  std::vector<std::vector<std::string>> values;
555  std::vector<ParameterABI::ErrorType> errors;
556  if(!function.abiOut(rawData, values, errors))
557  return false;
558  for(size_t i = 0; i < values.size(); i++)
559  {
560  std::vector<std::string> param = values[i];
561  output.push_back(param.size() ? param[0] : "");
562  }
563  }
564  else
565  {
566  QVariantMap variantMap = result.toMap();
567  d->txid = variantMap.value("txid").toString().toStdString();
568  }
569 
570  return true;
571 }
572 
573 bool Token::execEvents(int64_t fromBlock, int64_t toBlock, int func, std::vector<TokenEvent> &tokenEvents)
574 {
575  // Check parameters
576  if(func == -1 || fromBlock < 0)
577  return false;
578 
579  // Get function
580  FunctionABI function = d->ABI->functions[func];
581 
582  // Search for events
583  QVariant result;
584  std::string eventName = function.selector();
585  std::string contractAddress = d->lstParams[PARAM_ADDRESS].toStdString();
586  std::string senderAddress = d->lstParams[PARAM_SENDER].toStdString();
587  ToHash160(senderAddress, senderAddress);
588  senderAddress = "000000000000000000000000" + senderAddress;
589  if(!(d->eventLog->searchTokenTx(fromBlock, toBlock, contractAddress, senderAddress, result)))
590  return false;
591 
592  // Parse the result events
593  QList<QVariant> list = result.toList();
594  for(int i = 0; i < list.size(); i++)
595  {
596  // Search the log for events
597  QVariantMap variantMap = list[i].toMap();
598  QList<QVariant> listLog = variantMap.value("log").toList();
599  for(int i = 0; i < listLog.size(); i++)
600  {
601  // Skip the not needed events
602  QVariantMap variantLog = listLog[0].toMap();
603  QList<QVariant> topicsList = variantLog.value("topics").toList();
604  if(topicsList.count() < 3) continue;
605  if(topicsList[0].toString().toStdString() != eventName) continue;
606 
607  // Create new event
608  TokenEvent tokenEvent;
609  tokenEvent.address = variantMap.value("contractAddress").toString().toStdString();
610  tokenEvent.sender = topicsList[1].toString().toStdString().substr(24);
611  ToFabTokenAddress(tokenEvent.sender, tokenEvent.sender);
612  tokenEvent.receiver = topicsList[2].toString().toStdString().substr(24);
613  ToFabTokenAddress(tokenEvent.receiver, tokenEvent.receiver);
614  tokenEvent.blockHash = uint256S(variantMap.value("blockHash").toString().toStdString());
615  tokenEvent.blockNumber = variantMap.value("blockNumber").toLongLong();
616  tokenEvent.transactionHash = uint256S(variantMap.value("transactionHash").toString().toStdString());
617 
618  // Parse data
619  std::string data = variantLog.value("data").toString().toStdString();
620  dev::bytes rawData = dev::fromHex(data);
621  dev::bytesConstRef o(&rawData);
623  tokenEvent.value = u256Touint(outData);
624 
625  tokenEvents.push_back(tokenEvent);
626  }
627  }
628 
629  return true;
630 }
int funcAllowance
Definition: token.cpp:48
QMap< QString, QString > lstParams
Definition: token.cpp:31
std::string address
Definition: token.cpp:32
int evtTransfer
Definition: token.cpp:49
int funcName
Definition: token.cpp:37
int funcBalanceOf
Definition: token.cpp:43
TokenData * d
Definition: token.h:77
bool ToFabTokenAddress(const std::string &strHash160, std::string &strFabTokenAddress)
Definition: token.cpp:88
std::string getTxId()
Definition: token.cpp:259
base58-encoded Fabcoin addresses.
Definition: base58.h:104
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
uint64_t blockNumber
Definition: token.h:12
bool decimals(std::string &result, bool sendTo=false)
Definition: token.cpp:343
bool burnEvents(std::vector< TokenEvent > &tokenEvents, int64_t fromBlock=0, int64_t toBlock=-1)
Definition: token.cpp:515
bool IsValid() const
Definition: base58.cpp:247
std::string toString(string32 const &_s)
Make normal string from fixed-length string.
Definition: CommonData.cpp:141
int funcTransferFrom
Definition: token.cpp:40
bool burn(const std::string &_value, bool &success, bool sendTo=false)
Definition: token.cpp:361
uint256 value
Definition: token.h:14
std::vector< FunctionABI > functions
Definition: contractabi.h:205
unsigned char * begin()
Definition: uint256.h:65
Token()
Definition: token.cpp:101
unsigned char * end()
Definition: uint256.h:70
bool searchTokenTx(int64_t fromBlock, int64_t toBlock, std::string strContractAddress, std::string strSenderAddress, QVariant &result)
searchTokenTx Search the event log for token transactions
Definition: eventlog.cpp:58
bool exec(const QMap< QString, QString > &params, QVariant &result, QString &resultJson, QString &errorMessage)
exec Execute the RPC command
std::string address
Definition: token.h:8
bool execEvents(int64_t fromBlock, int64_t toBlock, int func, std::vector< TokenEvent > &tokenEvents)
Definition: token.cpp:573
bytes abiIn(std::string _id, T const &..._t)
Definition: ABI.h:64
int funcDecimals
Definition: token.cpp:41
bool name(std::string &result, bool sendTo=false)
Definition: token.cpp:264
bytes fromHex(std::string const &_s, WhenError _throw=WhenError::DontThrow)
Definition: CommonData.cpp:99
bool totalSupply(std::string &result, bool sendTo=false)
Definition: token.cpp:303
T abiOut(bytes const &_data)
Definition: ABI.h:88
uint256 uint256S(const char *str)
Definition: uint256.h:153
void setAddress(const std::string &address)
Definition: token.cpp:217
bool burnFrom(const std::string &_from, const std::string &_value, bool &success, bool sendTo=false)
Definition: token.cpp:412
std::vector< byte > bytes
Definition: Common.h:75
bool allowance(const std::string &_from, const std::string &_to, std::string &result, bool sendTo=false)
Definition: token.cpp:489
bool exec(const std::vector< std::string > &input, int func, std::vector< std::string > &output, bool sendTo)
Definition: token.cpp:520
void setDataHex(const std::string &datahex)
Definition: token.cpp:222
int funcTransfer
Definition: token.cpp:46
std::string ToString() const
Definition: base58.cpp:193
std::string name
Definition: contractabi.h:180
void setGasLimit(const std::string &gaslimit)
Definition: token.cpp:232
bool transferEvents(std::vector< TokenEvent > &tokenEvents, int64_t fromBlock=0, int64_t toBlock=-1)
Definition: token.cpp:510
void setGasPrice(const std::string &gasPrice)
Definition: token.cpp:237
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
Definition: Common.h:125
int funcTotalSupply
Definition: token.cpp:39
std::string txid
Definition: token.cpp:52
std::string FormatMoney(const CAmount &n)
Money parsing/formatting utilities.
int funcSymbol
Definition: token.cpp:45
int funcApproveAndCall
Definition: token.cpp:47
int funcBurnFrom
Definition: token.cpp:44
bool symbol(std::string &result, bool sendTo=false)
Definition: token.cpp:433
bool transfer(const std::string &_to, const std::string &_value, bool sendTo=false)
Definition: token.cpp:451
int funcBurn
Definition: token.cpp:42
int evtBurn
Definition: token.cpp:50
bool ToHash160(const std::string &strFabTokenAddress, std::string &strHash160)
Definition: token.cpp:75
EventLog * eventLog
Definition: token.cpp:35
bool GetKeyID(CKeyID &keyID) const
Definition: base58.cpp:274
uint256 u256Touint(const dev::u256 &in)
Definition: uint256.h:191
void setAmount(const std::string &amount)
Definition: token.cpp:227
The ExecRPCCommand class Execution of RPC command line.
ContractABI * ABI
Definition: token.cpp:36
TokenData()
Definition: token.cpp:54
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:29
160-bit opaque blob.
Definition: uint256.h:120
uint256 transactionHash
Definition: token.h:13
int funcApprove
Definition: token.cpp:38
bool balanceOf(std::string &result, bool sendTo=false)
Definition: token.cpp:381
bool loads(const std::string &json_data)
Definition: contractabi.cpp:54
std::vector< unsigned char > valtype
Definition: fascstate.h:17
bool approveAndCall(const std::string &_spender, const std::string &_value, const std::string &_extraData, bool &success, bool sendTo=false)
Definition: token.cpp:467
ExecRPCCommand * call
Definition: token.cpp:33
#define d(i)
Definition: sha.cpp:732
struct evm_uint160be address(struct evm_env *env)
Definition: capi.c:13
std::string receiver
Definition: token.h:10
~Token()
Definition: token.cpp:198
ExecRPCCommand * send
Definition: token.cpp:34
uint256 blockHash
Definition: token.h:11
void setSender(const std::string &sender)
Definition: token.cpp:242
bool transferFrom(const std::string &_from, const std::string &_to, const std::string &_value, bool &success, bool sendTo=false)
Definition: token.cpp:321
uint8_t const * data
Definition: sha3.h:19
bool approve(const std::string &_spender, const std::string &_value, bool &success, bool sendTo=false)
Definition: token.cpp:282
bool Set(const CKeyID &id)
Definition: base58.cpp:230
std::string sender
Definition: token.h:9
void clear()
Definition: token.cpp:247
std::vector< unsigned char > ParseHex(const char *psz)