diff --git a/common/config/config.go b/common/config/config.go index 186e6b8f7..0dacdad4a 100644 --- a/common/config/config.go +++ b/common/config/config.go @@ -250,6 +250,17 @@ func GetTrackDestroyedContractHeight() uint32 { } } +func GetAddDecimalsHeight() uint32 { + switch DefConfig.P2PNode.NetworkId { + case NETWORK_ID_MAIN_NET: + return constants.BLOCKHEIGHT_ADD_DECIMALS_MAINNET + case NETWORK_ID_POLARIS_NET: + return constants.BLOCKHEIGHT_ADD_DECIMALS_POLARIS + default: + return 0 + } +} + // the end of unbound timestamp offset from genesis block's timestamp func GetGovUnboundDeadline() (uint32, uint64) { count := uint64(0) diff --git a/common/constants/constants.go b/common/constants/constants.go index 0dee7a95a..6ff5c1c89 100644 --- a/common/constants/constants.go +++ b/common/constants/constants.go @@ -114,3 +114,6 @@ const BLOCKHEIGHT_NEW_PEER_COST_POLARIS = 13400000 const BLOCKHEIGHT_TRACK_DESTROYED_CONTRACT_MAINNET = 11700000 const BLOCKHEIGHT_TRACK_DESTROYED_CONTRACT_POLARIS = 14100000 + +const BLOCKHEIGHT_ADD_DECIMALS_MAINNET = 13430000 +const BLOCKHEIGHT_ADD_DECIMALS_POLARIS = 0 diff --git a/docs/specifications/restful_api.md b/docs/specifications/restful_api.md index 4c15362e7..5ec0a8200 100644 --- a/docs/specifications/restful_api.md +++ b/docs/specifications/restful_api.md @@ -48,6 +48,8 @@ This document describes the restful api format for the http/https used in the On | [get_networkid](#22-get_networkid) | GET /api/v1/networkid | return the networkid | | [get_grantong](#23-get_grantong) | GET /api/v1/grantong/:addr | get grant ong | | [get_syncstatus](#24-get_syncstatus) | GET /api/v1/node/syncstatus |gets the synchronization status of the node | +| [get_balancev2](#25-get_balancev2) | GET /api/v1/balance/:addr | return balance of the account address,ont decimals is 9,ong decimals is 18 | +| [get_allowancev2](#26-get_allowancev2) | GET /api/v1/allowance/:asset/:from/:to | return the allowance from transfer-from accout to transfer-to account, ont decimals is 9,ong decimals is 18 | ### 1 get_conn_count @@ -903,6 +905,60 @@ curl -i http://localhost:20334/api/v1/node/syncstatus } ``` + +### 25 get_balancev2 + +return balance of the account address,ont decimals is 9,ong decimals is 18 + +GET +``` +/api/v1/balancev2/:addr +``` +> addr: Base58 encoded address + +#### Request Example +``` +curl -i http://localhost:20334/api/v1/balancev2/TA5uYzLU2vBvvfCMxyV2sdzc9kPqJzGZWq +``` + +#### Response +``` +{ + "Action": "getbalancev2", + "Desc": "SUCCESS", + "Error": 0, + "Result": { + "ont": "999999996000000000", + "ong": "999999998000000000000000000", + "height":"1455" + }, + "Version": "1.0.0" +} +``` + +### 26 get_allowancev2 + +return the allowance from transfer-from accout to transfer-to account, ont decimals is 9,ong decimals is 18 + +GET +``` +/api/v1/allowancev2 +``` +#### Request Example: +``` +curl -i http://localhost:20334/api/v1/allowancev2/:asset/:from/:to +``` +#### Response +``` +{ + "Action": "getallowancev2", + "Desc": "SUCCESS", + "Error": 0, + "Result": "10000000000", + "Version": "1.0.0" +} +``` + ## Error Code | Field | Type | Description | diff --git a/docs/specifications/restful_api_CN.md b/docs/specifications/restful_api_CN.md index aa31ee426..de37d66dc 100644 --- a/docs/specifications/restful_api_CN.md +++ b/docs/specifications/restful_api_CN.md @@ -48,6 +48,8 @@ | [get_networkid](#22-get_networkid) | GET /api/v1/networkid | 得到network id | | [get_grantong](#23-get_grantong) | GET /api/v1/grantong/:addr | 得到grant ong | | [get_syncstatus](#24-get_syncstatus) | GET /api/v1/node/syncstatus | 得到节点同步状态 | +| [get_balancev2](#25-get_balancev2) | GET /api/v1/balance/:addr | 得到该地址的账户的余额,ont精度9,ong精度18 | +| [get_allowancev2](#26-get_allowancev2) | GET /api/v1/allowance/:asset/:from/:to | 返回允许从from账户转出到to账户的额度,ont精度9,ong精度18 | ### 1 get_conn_count @@ -900,6 +902,60 @@ curl -i http://localhost:20334/api/v1/node/syncstatus } ``` + +### 25 get_balancev2 + +得到该地址的账户的余额。ont精度9,ong精度18 + +GET +``` +/api/v1/balancev2/:addr +``` +> addr: Base58编码后的账户地址 + +#### Request Example +``` +curl -i http://localhost:20334/api/v1/balancev2/TA5uYzLU2vBvvfCMxyV2sdzc9kPqJzGZWq +``` + +#### Response +``` +{ + "Action": "getbalancev2", + "Desc": "SUCCESS", + "Error": 0, + "Result": { + "ont": "999999996000000000", + "ong": "999999998000000000000000000", + "height":"1455" + }, + "Version": "1.0.0" +} +``` + +### 26 get_allowancev2 + +得到允许从from账户转出到to账户的额度。ont精度9,ong精度18 + +GET +``` +/api/v1/allowancev2 +``` +#### Request Example: +``` +curl -i http://localhost:20334/api/v1/allowancev2/:asset/:from/:to +``` +#### Response +``` +{ + "Action": "getallowancev2", + "Desc": "SUCCESS", + "Error": 0, + "Result": "10000000000", + "Version": "1.0.0" +} +``` + ## 错误代码 | Field | Type | Description | diff --git a/docs/specifications/rpc_api.md b/docs/specifications/rpc_api.md index f4c30bb29..b6cebd3ea 100644 --- a/docs/specifications/rpc_api.md +++ b/docs/specifications/rpc_api.md @@ -98,6 +98,8 @@ There are some description of parameter used in rpc: | [getnetworkid](#21-getnetworkid) | | Get the network id | | | [getgrantong](#22-getgrantong) | | Get grant ong | | | [getsyncstatus](#23-getsyncstatus) | | Get the synchronization status of the node | | +| [getbalancev2](#24-getbalancev2) | address | return balance of the account address,ont decimals is 9,ong decimals is 18 | | +| [getallowancev2](#25-getallowancev2) | asset, from, to | return the allowance from transfer-from accout to transfer-to account, ont decimals is 9,ong decimals is 18 | | ### 1. getbestblockhash @@ -1135,6 +1137,81 @@ Response: } ``` +#### 24. getbalancev2 + +return balance of the account address,ont decimals is 9,ong decimals is 18 + +#### 参数定义 + +address: base58 encoded address + +#### Example + +Request: + +``` +{ + "jsonrpc": "2.0", + "method": "getbalancev2", + "params": ["TA5uYzLU2vBvvfCMxyV2sdzc9kPqJzGZWq"], + "id": 1 +} +``` + +Response: + +``` +{ + "desc":"SUCCESS", + "error":0, + "id":1, + "jsonrpc":"2.0", + "result":{ + "ont": "999999996000000000", + "ong": "999999998000000000000000000", + "height":"1455" + } +} +``` + + +#### 25. getallowancev2 + +return the allowance from transfer-from accout to transfer-to account, ont decimals is 9,ong decimals is 18 + +#### 参数定义 + +asset: "ont" or "ong" + +from: transfer out base58 encoded address + +to: transfer in base58 encoded address + +#### Example + +Request: + +``` +{ + "jsonrpc": "2.0", + "method": "getallowancev2", + "params": ["ont","from address","to address"], + "id": 1 +} +``` + +Response: + +``` +{ + "desc":"SUCCESS", + "error":0, + "id":1, + "jsonrpc":"2.0", + "result": "100000000000" +} +``` + ## Error Code diff --git a/docs/specifications/rpc_api_CN.md b/docs/specifications/rpc_api_CN.md index be120f264..2f92dbfdb 100644 --- a/docs/specifications/rpc_api_CN.md +++ b/docs/specifications/rpc_api_CN.md @@ -89,7 +89,7 @@ | [getmempooltxstate](#12-getmempooltxstate) | tx_hash | 查询内存中的交易的状态 | | | [getsmartcodeevent](#13-getsmartcodeevent) | | 得到智能合约执行的结果 | | | [getblockheightbytxhash](#14-getblockheightbytxhash) | tx_hash | 得到该交易哈希所落账的区块的高度 | | -| [getbalance](#15-getbalance) | address | 返回base58地址的余额 | | +| [getbalance](#15-getbalance) | address | 返回base58地址的余额, ont精度0,ong精度9 | | | [getmerkleproof](#16-getmerkleproof) | tx_hash | 返回merkle证明 | | | [getgasprice](#17-getgasprice) | | 返回gas的价格 | | | [getallowance](#18-getallowance) | asset, from, to | 返回允许从from转出到to账户的额度 | | @@ -98,6 +98,8 @@ | [getnetworkid](#21-getnetworkid) | | 获取 network id | | | [getgrantong](#22-getgrantong) | | 获取 grant ong | | | [getsyncstatus](#23-getsyncstatus) | | 获取 节点同步的状态 | | +| [getbalancev2](#24-getbalancev2) | address | 返回base58地址的余额, ont精度9, ong精度18 | | +| [getallowancev2](#25-getallowancev2) | asset, from, to | 返回允许从from转出到to账户的额度,ont精度9, ong精度18 | | ### 1. getbestblockhash @@ -1147,6 +1149,82 @@ Response: } ``` +#### 24. getbalancev2 + +返回base58地址的余额, ont精度9, ong精度18 + +#### 参数定义 + +address: base58地址 + +#### Example + +Request: + +``` +{ + "jsonrpc": "2.0", + "method": "getbalance", + "params": ["TA5uYzLU2vBvvfCMxyV2sdzc9kPqJzGZWq"], + "id": 1 +} +``` + +Response: + +``` +{ + "desc":"SUCCESS", + "error":0, + "id":1, + "jsonrpc":"2.0", + "result":{ + "ont": "999999996000000000", + "ong": "999999998000000000000000000", + "height":"1455" + } +} +``` + + +#### 25. getallowancev2 + +返回允许从from转出到to账户的额度, ont精度9, ong精度18 + +#### 参数定义 + +asset: "ont"或者"ong" + +from: 转出账户base58地址 + +to: 转入账户base58地址 + +#### Example + +Request: + +``` +{ + "jsonrpc": "2.0", + "method": "getallowancev2", + "params": ["ont","from address","to address"], + "id": 1 +} +``` + +Response: + +``` +{ + "desc":"SUCCESS", + "error":0, + "id":1, + "jsonrpc":"2.0", + "result": "100000000000" +} +``` + + ## 错误代码 错误码定义 diff --git a/docs/specifications/websocket_api.md b/docs/specifications/websocket_api.md index c87b707d2..5243bfb5c 100644 --- a/docs/specifications/websocket_api.md +++ b/docs/specifications/websocket_api.md @@ -52,6 +52,8 @@ This document describes the Websocket api format for the ws/wss used in the Onch | [getnetworkid](#25-getnetworkid) | | get the network id | | [getgrantong](#26-getgrantong) | | get grant ong | | [getsyncstatus](#27-getsyncstatus) | | gets the synchronization status of the node | +| [getbalancev2](#12-getbalancev2) | address | return balance of the account address,ont decimals is 9,ong decimals is 18 | +| [getallowancev2](#20-getallowancev2) | asset, from, to | return the allowance from transfer-from accout to transfer-to account, ont decimals is 9,ong decimals is 18 | ### 1. heartbeat @@ -991,6 +993,62 @@ gets the synchronization status of the node } ``` +### 28. getbalancev2 + +return balance of the account address,ont decimals is 9,ong decimals is 18 + + +#### Request Example +``` +{ + "Action": "getbalancev2", + "Version": "1.0.0", + "Id":12345, //optional + "Addr": "TA63xZXqdPLtDeznWQ6Ns4UsbqprLrrLJk" +} +``` + +#### Response Example +``` +{ + "Action": "getbalancev2", + "Desc": "SUCCESS", + "Error": 0, + "Result": { + "ont": "999999996000000000", + "ong": "999999998000000000000000000", + "height":"1455" + }, + "Version": "1.0.0" +} +``` + + +### 29. getallowancev2 + +return the allowance from transfer-from accout to transfer-to account, ont decimals is 9,ong decimals is 18. + +#### Request Example: +``` +{ + "Action": "getallowancev2", + "Id":12345, //optional + "Asset": "ont", + "From" : "A9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb", + "To" : "AA4WVfUB1ipHL8s3PRSYgeV1HhAU3KcKTq", + "Version": "1.0.0" +} +``` +#### Response Example +``` +{ + "Action": "getallowancev2", + "Desc": "SUCCESS", + "Error": 0, + "Result": "10000000000", + "Version": "1.0.0" +} +``` ## Error Code diff --git a/docs/specifications/websocket_api_CN.md b/docs/specifications/websocket_api_CN.md index 5907ed7b1..325826731 100644 --- a/docs/specifications/websocket_api_CN.md +++ b/docs/specifications/websocket_api_CN.md @@ -52,6 +52,8 @@ | [getnetworkid](#25-getnetworkid) | | 得到network id | | [getgrantong](#26-getgrantong) | | 得到grant ong | | [getsyncstatus](#27-getsyncstatus) | | 得到节点的同步状态 | +| [getbalancev2](#12-getbalancev2) | address | 得到该地址的账户的余额,ont精度9,ong精度18 | +| [getallowancev2](#20-getallowancev2) | asset, from, to | 返回允许从from账户转出到to账户的额度, ont精度9,ong精度18 | ### 1. heartbeat @@ -996,6 +998,63 @@ raw:可选参数,默认值为零,不设置时为默认值。当值为1时 ``` +### 28. getbalancev2 + +得到该地址的账户的余额。 + + +#### Request Example +``` +{ + "Action": "getbalancev2", + "Version": "1.0.0", + "Id":12345, //optional + "Addr": "TA63xZXqdPLtDeznWQ6Ns4UsbqprLrrLJk" +} +``` + +#### Response Example +``` +{ + "Action": "getbalancev2", + "Desc": "SUCCESS", + "Error": 0, + "Result": { + "ont": "999999996000000000", + "ong": "999999998000000000000000000", + "height":"1455" + }, + "Version": "1.0.0" +} +``` + + +### 29. getallowancev2 + +得到允许从from账户转出到to账户的额度。 + +#### Request Example: +``` +{ + "Action": "getallowancev2", + "Id":12345, //optional + "Asset": "ont", + "From" : "A9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb", + "To" : "AA4WVfUB1ipHL8s3PRSYgeV1HhAU3KcKTq", + "Version": "1.0.0" +} +``` +#### Response Example +``` +{ + "Action": "getallowancev2", + "Desc": "SUCCESS", + "Error": 0, + "Result": "10000000000", + "Version": "1.0.0" +} +``` + ## 错误代码 | Field | Type | Description | diff --git a/smartcontract/service/native/ong/ong.go b/smartcontract/service/native/ong/ong.go index a6b8c4ab2..4716072b1 100644 --- a/smartcontract/service/native/ong/ong.go +++ b/smartcontract/service/native/ong/ong.go @@ -23,12 +23,10 @@ import ( "math/big" "github.com/laizy/bigint" - - "github.com/ontio/ontology/core/states" - "github.com/ontio/ontology/common" "github.com/ontio/ontology/common/config" "github.com/ontio/ontology/common/constants" + "github.com/ontio/ontology/core/states" "github.com/ontio/ontology/core/types" "github.com/ontio/ontology/errors" "github.com/ontio/ontology/smartcontract/service/native" @@ -54,14 +52,17 @@ func RegisterOngContract(native *native.NativeService) { native.Register(ont.ALLOWANCE_NAME, OngAllowance) native.Register(ont.TOTAL_ALLOWANCE_NAME, OngTotalAllowance) - native.Register(ont.TRANSFER_V2_NAME, OngTransferV2) - native.Register(ont.APPROVE_V2_NAME, OngApproveV2) - native.Register(ont.TRANSFERFROM_V2_NAME, OngTransferFromV2) - native.Register(ont.DECIMALS_V2_NAME, OngDecimalsV2) - native.Register(ont.TOTAL_SUPPLY_V2_NAME, OngTotalSupplyV2) - native.Register(ont.BALANCEOF_V2_NAME, OngBalanceOfV2) - native.Register(ont.ALLOWANCE_V2_NAME, OngAllowanceV2) - native.Register(ont.TOTAL_ALLOWANCE_V2_NAME, OngTotalAllowanceV2) + if native.Height >= config.GetAddDecimalsHeight() { + native.Register(ont.TRANSFER_V2_NAME, OngTransferV2) + native.Register(ont.APPROVE_V2_NAME, OngApproveV2) + native.Register(ont.TRANSFERFROM_V2_NAME, OngTransferFromV2) + native.Register(ont.DECIMALS_V2_NAME, OngDecimalsV2) + native.Register(ont.TOTAL_SUPPLY_V2_NAME, OngTotalSupplyV2) + native.Register(ont.BALANCEOF_V2_NAME, OngBalanceOfV2) + native.Register(ont.ALLOWANCE_V2_NAME, OngAllowanceV2) + native.Register(ont.TOTAL_ALLOWANCE_V2_NAME, OngTotalAllowanceV2) + } + } func OngInit(native *native.NativeService) ([]byte, error) { diff --git a/smartcontract/service/native/ont/ont.go b/smartcontract/service/native/ont/ont.go index 6fa207cc5..0df23f07d 100644 --- a/smartcontract/service/native/ont/ont.go +++ b/smartcontract/service/native/ont/ont.go @@ -24,7 +24,6 @@ import ( "math/big" "github.com/laizy/bigint" - "github.com/ontio/ontology/common" "github.com/ontio/ontology/common/config" "github.com/ontio/ontology/common/constants" @@ -57,14 +56,16 @@ func RegisterOntContract(native *native.NativeService) { native.Register(ALLOWANCE_NAME, OntAllowance) native.Register(TOTAL_ALLOWANCE_NAME, TotalAllowance) - native.Register(TRANSFER_V2_NAME, OntTransferV2) - native.Register(APPROVE_V2_NAME, OntApproveV2) - native.Register(TRANSFERFROM_V2_NAME, OntTransferFromV2) - native.Register(DECIMALS_V2_NAME, OntDecimalsV2) - native.Register(TOTAL_SUPPLY_V2_NAME, OntTotalSupplyV2) - native.Register(BALANCEOF_V2_NAME, OntBalanceOfV2) - native.Register(ALLOWANCE_V2_NAME, OntAllowanceV2) - native.Register(TOTAL_ALLOWANCE_V2_NAME, TotalAllowanceV2) + if native.Height >= config.GetAddDecimalsHeight() { + native.Register(TRANSFER_V2_NAME, OntTransferV2) + native.Register(APPROVE_V2_NAME, OntApproveV2) + native.Register(TRANSFERFROM_V2_NAME, OntTransferFromV2) + native.Register(DECIMALS_V2_NAME, OntDecimalsV2) + native.Register(TOTAL_SUPPLY_V2_NAME, OntTotalSupplyV2) + native.Register(BALANCEOF_V2_NAME, OntBalanceOfV2) + native.Register(ALLOWANCE_V2_NAME, OntAllowanceV2) + native.Register(TOTAL_ALLOWANCE_V2_NAME, TotalAllowanceV2) + } native.Register(UNBOUND_ONG_TO_GOVERNANCE, UnboundOngToGovernance) } diff --git a/txnpool/proc/txnpool_actor.go b/txnpool/proc/txnpool_actor.go index d03271d9f..c83b7b63d 100644 --- a/txnpool/proc/txnpool_actor.go +++ b/txnpool/proc/txnpool_actor.go @@ -150,6 +150,11 @@ func (ta *TxPoolService) handleTransaction(sender tc.SenderType, txn *tx.Transac } if txn.IsEipTx() { + curBlkHeight := ledger.DefLedger.GetCurrentBlockHeight() + if curBlkHeight < config.GetAddDecimalsHeight() { + replyTxResult(txResultCh, txn.Hash(), errors.ErrUnknown, "block height is not reached, evm is not support") + return + } if txn.GasLimit > config.DefConfig.Common.ETHTxGasLimit { replyTxResult(txResultCh, txn.Hash(), errors.ErrUnknown, "EIP155 tx gaslimit exceed ") return @@ -161,7 +166,6 @@ func (ta *TxPoolService) handleTransaction(sender tc.SenderType, txn *tx.Transac replyTxResult(txResultCh, txn.Hash(), errors.ErrUnknown, "Invalid EIP155 transaction format ") return } - currentNonce := ta.server.CurrentNonce(txn.Payer) if eiptx.Nonce() < currentNonce { replyTxResult(txResultCh, txn.Hash(), errors.ErrUnknown,