message: Add getcontractcode method to get code from contract
diff: @@ -950,6 +950,30 @@ static UniValue getaccountinfo(const JSONRPCRequest& request)
  }
  return result;
  }
  +// Get contract code method
  +static UniValue getcontractcode(const JSONRPCRequest& request)
  +{
  + if (request.fHelp || request.params.size() < 1)
  + throw std::runtime_error(
  + "getcontractcode \"address\"\n"
  + "\nArgument:\n"
  + "1. \"address\" (string, required) The contract address\n"
  + );
  +
  + LOCK(cs_main);
  +
  + std::string strAddr = request.params[0].get_str();
  + if(strAddr.size() != 40 || !CheckHex(strAddr))
  + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Incorrect address");
  +
  + dev::Address addrAccount(strAddr);
  + if(!globalState->addressInUse(addrAccount))
  + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Address does not exist");
  +
  + std::vector<uint8_t> code(globalState->code(addrAccount));
  +
  + return HexStr(code.begin(), code.end());
  +}
  static UniValue getstorage(const JSONRPCRequest& request)
  {
  @@ -3379,6 +3403,7 @@ static const CRPCCommand commands[] =
  { "blockchain", "savemempool", &savemempool, {} },
  { "blockchain", "verifychain", &verifychain, {"checklevel","nblocks"} },
  { "blockchain", "getaccountinfo", &getaccountinfo, {"contract_address"} },
  + { "blockchain", "getcontractcode", &getcontractcode, {"contract_address"} },
  { "blockchain", "getstorage", &getstorage, {"address, index, blockNum"} },
  { "blockchain", "preciousblock", &preciousblock, {"blockhash"} },
  