tronprotocol / java-tron

Java implementation of the Tron whitepaper
GNU Lesser General Public License v3.0
3.74k stars 1.41k forks source link

Full node json-rpc API #5547

Closed 1scrooge closed 1 year ago

1scrooge commented 1 year ago

Hi. I enabled json-rpc api, but got an error HTTP ERROR 405 HTTP method POST is not supported by this URL

root@tron-testnet:~/node$ curl -X POST 'http://127.0.0.1:50545' --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":64}'
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 405 HTTP method POST is not supported by this URL</title>
</head>
<body><h2>HTTP ERROR 405 HTTP method POST is not supported by this URL</h2>
<table>
<tr><th>URI:</th><td>/</td></tr>
<tr><th>STATUS:</th><td>405</td></tr>
<tr><th>MESSAGE:</th><td>HTTP method POST is not supported by this URL</td></tr>
<tr><th>SERVLET:</th><td>org.eclipse.jetty.servlet.ServletHandler$Default404Servlet-690e7b89</td></tr>
</table>
<hr/><a href="https://eclipse.org/jetty">Powered by Jetty:// 9.4.49.v20220914</a><hr/>

</body>
</html>
root@tron-testnet:~/node$

My testnet config file:

net {
  type = mainnet
  # type = testnet
}

storage {
  # Directory for storing persistent data
  db.version = 2,
  db.engine = "LEVELDB",
  db.sync = false,
  db.directory = "database",
  index.directory = "index",
  transHistory.switch = "on",
  # You can custom these 14 databases' configs:

  # account, account-index, asset-issue, block, block-index,
  # block_KDB, peers, properties, recent-block, trans,
  # utxo, votes, witness, witness_schedule.

  # Otherwise, db configs will remain defualt and data will be stored in
  # the path of "output-directory" or which is set by "-d" ("--output-directory").

  # Attention: name is a required field that must be set !!!
  properties = [
    //    {
    //      name = "account",
    //      path = "storage_directory_test",
    //      createIfMissing = true,
    //      paranoidChecks = true,
    //      verifyChecksums = true,
    //      compressionType = 1,        // compressed with snappy
    //      blockSize = 4096,           // 4  KB =         4 * 1024 B
    //      writeBufferSize = 10485760, // 10 MB = 10 * 1024 * 1024 B
    //      cacheSize = 10485760,       // 10 MB = 10 * 1024 * 1024 B
    //      maxOpenFiles = 100
    //    },
    //    {
    //      name = "account-index",
    //      path = "storage_directory_test",
    //      createIfMissing = true,
    //      paranoidChecks = true,
    //      verifyChecksums = true,
    //      compressionType = 1,        // compressed with snappy
    //      blockSize = 4096,           // 4  KB =         4 * 1024 B
    //      writeBufferSize = 10485760, // 10 MB = 10 * 1024 * 1024 B
    //      cacheSize = 10485760,       // 10 MB = 10 * 1024 * 1024 B
    //      maxOpenFiles = 100
    //    },
  ]

  needToUpdateAsset = true

  //dbsettings is needed when using rocksdb as the storage implement (db.version=2 and db.engine="ROCKSDB").
  //we'd strongly recommend that do not modify it unless you know every item's meaning clearly.
  dbSettings = {
    levelNumber = 7
    //compactThreads = 32
    blocksize = 64  // n * KB
    maxBytesForLevelBase = 256  // n * MB
    maxBytesForLevelMultiplier = 10
    level0FileNumCompactionTrigger = 4
    targetFileSizeBase = 256  // n * MB
    targetFileSizeMultiplier = 1
  }

  //backup settings when using rocks db as the storage implement (db.version=2 and db.engine="ROCKSDB").
  //if you want to use the backup plugin, please confirm set the db.version=2 and db.engine="ROCKSDB" above.
  backup = {
    enable = false  // indicate whether enable the backup plugin
    propPath = "prop.properties" // record which bak directory is valid
    bak1path = "bak1/database" // you must set two backup directories to prevent application halt unexpected(e.g. kill -9).
    bak2path = "bak2/database"
    frequency = 10000   // indicate backup db once every 10000 blocks processed.
  }

  # if true, transaction cache initialization will be faster. default false
  # txCache.initOptimization = true
}

node.discovery = {
  enable = true
  persist = true
  bind.ip = ""
  external.ip = null
}

node.jsonrpc {
httpFullNodeEnable = true
httpFullNodePort = 50545
httpSolidityEnable = true
httpSolidityPort = 50555
}

node.backup {
  port = 10001

  # my priority, each member should use different priority
  priority = 8

  # peer's ip list, can't contain mine
  members = [
    # "ip",
    # "ip"
  ]
}

node {
  # trust node for solidity node
  # trustNode = "ip:port"
  trustNode = "127.0.0.1:50051"

  # expose extension api to public or not
  walletExtensionApi = true

  listen.port = 18888

  connection.timeout = 2

  tcpNettyWorkThreadNum = 0

  udpNettyWorkThreadNum = 1

  # Number of validate sign thread, default availableProcessors / 2
  # validateSignThreadNum = 16

  maxConnections = 30

  minConnections = 8

  minActiveConnections = 3

  maxActiveNodesWithSameIp = 2

  maxHttpConnectNumber = 50

  minParticipationRate = 15

  zenTokenId = 1000016

  # check the peer data transfer ,disconnect factor
  disconnectNumberFactor = 0.4
  maxConnectNumberFactor = 0.8
  receiveTcpMinDataLength = 2048
  isOpenFullTcpDisconnect = true

  p2p {
    version = 201910292
  }

  active = [
    # Active establish connection in any case
    # Sample entries:
    # "ip:port",
    # "ip:port"
  ]

  passive = [
    # Passive accept connection in any case
    # Sample entries:
    # "ip:port",
    # "ip:port"
  ]

  # read node.active and node.passive periodically, default false
  # checkInterval unit: second
  dynamicConfig {
    # enable = false
    # checkInterval = 600
  }

  fastForward = [
  ]

  http {
    fullNodePort = 8090
    solidityPort = 8091
  }

  # use your ipv6 address for node discovery and tcp connection, default false
  # enableIpv6 = false

  # if your node's highest block num is below than all your pees', try to acquire new connection. default false
  # effectiveCheckEnable = false

  # Enable node detect
  # nodeDetectEnable = false

  dns {
    # dns urls to get nodes, url format tree://{pubkey}@{domain}, default empty
    treeUrls = [
      #"tree://APFGGTFOBVE2ZNAB3CSMNNX6RRK3ODIRLP2AA5U4YFAA6MSYZUYTQ@nodes1.example.org",
    ]
  }
  rpc {
    port = 50051
    #solidityPort = 50061
    # Number of gRPC thread, default availableProcessors / 2
    # thread = 16

    # The maximum number of concurrent calls permitted for each incoming connection
    # maxConcurrentCallsPerConnection =

    # The HTTP/2 flow control window, default 1MB
    # flowControlWindow =

    # Connection being idle for longer than which will be gracefully terminated
    maxConnectionIdleInMillis = 60000

    # Connection lasting longer than which will be gracefully terminated
    # maxConnectionAgeInMillis =

    # The maximum message size allowed to be received on the server, default 4MB
    # maxMessageSize =

    # The maximum size of header list allowed to be received, default 8192
    # maxHeaderListSize =

    # Transactions can only be broadcast if the number of effective connections is reached.
    minEffectiveConnection = 1
  }

  # number of solidity thread in the FullNode.
  # If accessing solidity rpc and http interface timeout, could increase the number of threads,
  # The default value is the number of cpu cores of the machine.
  #solidity.threads = 8

  # Limits the maximum percentage (default 75%) of producing block interval
  # to provide sufficient time to perform other operations e.g. broadcast block
  # blockProducedTimeOut = 75

  # Limits the maximum number (default 700) of transaction from network layer
  # netMaxTrxPerSecond = 700

}

## rate limiter config
rate.limiter = {
  # Use global settings to limit the QPS of the entire node or every ip address
  # global.qps = 1000
  # global.ip.qps = 100

  # Every api could be set a specific rate limit strategy. Three strategy are supported:GlobalPreemptibleAdapter、IPQPSRateLimiterAdapte、QpsRateLimiterAdapter
  # GlobalPreemptibleAdapter: permit is the number of preemptible resource, every client must apply one resourse
  #       before do the request and release the resource after got the reponse automaticlly. permit should be a Integer.
  # QpsRateLimiterAdapter: qps is the average request count in one second supported by the server, it could be a Double or a Integer.
  # IPQPSRateLimiterAdapter: similar to the QpsRateLimiterAdapter, qps could be a Double or a Integer.
  # If do not set, the "default strategy" is set.The "default startegy" is based on QpsRateLimiterAdapter, the qps is set as 10000.
  #
  # Sample entries:
  #
  http = [
    #  {
    #    component = "GetNowBlockServlet",
    #    strategy = "GlobalPreemptibleAdapter",
    #    paramString = "permit=1"
    #  },

    #  {
    #    component = "GetAccountServlet",
    #    strategy = "IPQPSRateLimiterAdapter",
    #    paramString = "qps=1"
    #  },

    #  {
    #    component = "ListWitnessesServlet",
    #    strategy = "QpsRateLimiterAdapter",
    #    paramString = "qps=1"
    #  }
  ],

  rpc = [
    #  {
    #    component = "protocol.Wallet/GetBlockByLatestNum2",
    #    strategy = "GlobalPreemptibleAdapter",
    #    paramString = "permit=1"
    #  },

    #  {
    #    component = "protocol.Wallet/GetAccount",
    #    strategy = "IPQPSRateLimiterAdapter",
    #    paramString = "qps=1"
    #  },

    #  {
    #    component = "protocol.Wallet/ListWitnesses",
    #    strategy = "QpsRateLimiterAdapter",
    #    paramString = "qps=1"
    #  },
  ]
}

seed.node = {
  # List of the seed nodes
  # Seed nodes are stable full nodes
  # example:
  # ip.list = [
  #   "ip:port",
  #   "ip:port"
  # ]
  ip.list = [
    "47.90.214.183:18888",
    "47.252.17.40:18888",
    "47.253.34.98:18888",
    "47.252.3.238:18888",
    "47.90.243.177:18888",
    "44.236.192.97:18888",
    "44.236.125.107:18888",
    "44.232.119.174:18888",
    "35.167.210.93:18888",
    "34.208.18.175:18888"
  ]
}

genesis.block = {
  # Reserve balance
  assets = [
    {
      accountName = "Zion"
      accountType = "AssetIssue"
      address = "TMWXhuxiT1KczhBxCseCDDsrhmpYGUcoA9"
      balance = "99000000000000000"
    },
    {
      accountName = "Sun"
      accountType = "AssetIssue"
      address = "TN21Wx2yoNYiZ7znuQonmZMJnH5Vdfxu78"
      balance = "99000000000000000"
    },
    {
      accountName = "Blackhole"
      accountType = "AssetIssue"
      address = "TDPJULRzVtzVjnBmZvfaTcTNQ2tsVi6XxQ"
      balance = "-9223372036854775808"
    }
  ]

  witnesses = [
    {
      address: TD23EqH3ixYMYh8CMXKdHyQWjePi3KQvxV,
      url = "http://GR1.com",
      voteCount = 100000026
    },
    {
      address: TCm4Lz1uP3tQm3jzpwFTG6o5UvSTA2XEHc,
      url = "http://GR2.com",
      voteCount = 100000025
    },
    {
      address: TTgDUgREiPBeY3iudD5e2eEibE4v4CE8C9,
      url = "http://GR3.com",
      voteCount = 100000024
    },
    {
      address: TFVDe7kMEmb8EuUxxp42kocQY1fFY727WS,
      url = "http://GR4.com",
      voteCount = 100000023
    },
    {
      address: TY4NSjctzTchHkhaCskVc5zQtnX9s1uxAX,
      url = "http://GR5.com",
      voteCount = 100000022
    },
    {
      address: TWSMPrm6aizvsJmPnjMB7x3UExJfRhyQhd,
      url = "http://GR6.com",
      voteCount = 100000021
    },
    {
      address: TKwLkSaCvqqpAB44qaHGTohCTCFoYw7ecy,
      url = "http://GR7.com",
      voteCount = 100000020
    },
    {
      address: TDsYmm1St9r4UZebDGWBcTMtfYTw9YX5h4,
      url = "http://GR8.com",
      voteCount = 100000019
    },
    {
      address: TFEQbWAPxhbUr1P14y9UJBUZo3LgtdqTS7,
      url = "http://GR9.com",
      voteCount = 100000018
    },
    {
      address: TCynAi8tb7UWP7uhLv6fe971KLm2KT8tcs,
      url = "http://GR10.com",
      voteCount = 100000017
    },
    {
      address: TC2YsLp4rzrt3AbeN3EryoSywrBjEUVCq3,
      url = "http://GR11.com",
      voteCount = 100000016
    },
    {
      address: THxMKH1uaL5FpURujkQR7u2sNZ2n5PSsiH,
      url = "http://GR12.com",
      voteCount = 100000015
    },
    {
      address: TWbzgoHimDcXWy19ts1An8bxA4JKjcYHeG,
      url = "http://GR13.com",
      voteCount = 100000014
    },
    {
      address: TW2LmXnVCEaxuVtQN8gZR1ixT5PNm4QLft,
      url = "http://GR14.com",
      voteCount = 100000013
    },
    {
      address: TVuqk4rYYVHVA6j6sSEnaLexhhoQhN8nyZ,
      url = "http://GR15.com",
      voteCount = 100000012
    },
    {
      address: TVMZu5ptZPhhkZ3Kaagkq35FmyuKNvUKJV,
      url = "http://GR16.com",
      voteCount = 100000011
    },
    {
      address: TFDHT8PqUrL2Bd8DeysSiHHBAEMidZgkhx,
      url = "http://GR17.com",
      voteCount = 100000010
    },
    {
      address: TVqz5Bj3M1uEenaSsw2NnXvTWChPj6K3hb,
      url = "http://GR18.com",
      voteCount = 100000009
    },
    {
      address: TSt8YNpARJkhdMdEV4C7ajH1tFHpZWzF1T,
      url = "http://GR19.com",
      voteCount = 100000008
    },
    {
      address: TTxWDjEb3Be1Ax8BCvK48cnaorZofLq2C9,
      url = "http://GR20.com",
      voteCount = 100000007
    },
    {
      address: TU5T838YtyZtEQKpnXEdRz3d8hJn6WHhjw,
      url = "http://GR21.com",
      voteCount = 100000006
    },
    {
      address: TRuSs1MpL3o2hzhU8r6HLC7WtDyVE9hsF6,
      url = "http://GR22.com",
      voteCount = 100000005
    },
    {
      address: TYMCoCZyAjWkWdUfEHg1oZQYbLKev282ou,
      url = "http://GR23.com",
      voteCount = 100000004
    },
    {
      address: TQvAyGATpLZymHbpeaRozJCKqSeRWVNhCJ,
      url = "http://GR24.com",
      voteCount = 100000003
    },
    {
      address: TYDd9nskbhJmLLNoe4yV2Z1SYtGjNa8wyg,
      url = "http://GR25.com",
      voteCount = 100000002
    },
    {
      address: TS5991Geh2qeHtw46rskpJyn6hFNbuZGGc,
      url = "http://GR26.com",
      voteCount = 100000001
    },
    {
      address: TKnn5MBnmXXeKdu9dxKVfKk4n1YdCeSRGr,
      url = "http://GR27.com",
      voteCount = 100000000
    }
  ]

  timestamp = "0" #2017-8-26 12:00:00

  parentHash = "0xe58f33f9baf9305dc6f82b9f1934ea8f0ade2defb951258d50167028c780351f"
}

// Optional.The default is empty.
// It is used when the witness account has set the witnessPermission.
// When it is not empty, the localWitnessAccountAddress represents the address of the witness account,
// and the localwitness is configured with the private key of the witnessPermissionAddress in the witness account.
// When it is empty,the localwitness is configured with the private key of the witness account.

//localWitnessAccountAddress =

#localwitnesskeystore = [
#  "localwitnesskeystore.json"
#]

block = {
  needSyncCheck = false
  maintenanceTimeInterval = 600000
  proposalExpireTime = 600000 //
}

# Transaction reference block, default is "head", configure to "solid" can avoid TaPos error
# trx.reference.block = "head" // head;solid;

# This property sets the number of milliseconds after the creation of the transaction that is expired, default value is  60000.
# trx.expiration.timeInMilliseconds = 60000

vm = {
  supportConstant =true
  minTimeRatio = 0.0
  maxTimeRatio = 5.0
  saveInternalTx = true

  # In rare cases, transactions that will be within the specified maximum execution time (default 10(ms)) are re-executed and packaged
  # longRunningTime = 10
}

committee = {
  allowCreationOfContracts = 0  //mainnet:0 (reset by committee),test:1
  allowAdaptiveEnergy = 0  //mainnet:0 (reset by committee),test:1
}

event.subscribe = {
  native = {
    useNativeQueue = true // if true, use native message queue, else use event plugin.
    bindport = 5555 // bind port
    sendqueuelength = 1000 //max length of send queue
  }

  path = "" // absolute path of plugin
  server = "" // target server address to receive event triggers
  dbconfig = "" // dbname|username|password
  contractParse = true,
  topics = [
    {
      triggerName = "block" // block trigger, the value can't be modified
      enable = false
      topic = "block" // plugin topic, the value could be modified
    },
    {
      triggerName = "transaction"
      enable = false
      topic = "transaction"
    },
    {
      triggerName = "contractevent"
      enable = false
      topic = "contractevent"
    },
    {
      triggerName = "contractlog"
      enable = false
      topic = "contractlog"
    }
  ]

  filter = {
    fromblock = "" // the value could be "", "earliest" or a specified block number as the beginning of the queried range
    toblock = "" // the value could be "", "latest" or a specified block number as end of the queried range
    contractAddress = [
      "" // contract address you want to subscribe, if it's set to "", you will receive contract logs/events with any contract address.
    ]

    contractTopic = [
      "" // contract topic you want to subscribe, if it's set to "", you will receive contract logs/events with any contract topic.
    ]
  }
}

What did I do wrong?

tomatoishealthy commented 1 year ago

You should use curl -X POST 'http://127.0.0.1:50545/jsonrpc' --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":64}'

1scrooge commented 1 year ago

so easy)) @tomatoishealthy thank you