Skip to content

Commit 2bf49f4

Browse files
Seulgi Kimsgkim126
authored andcommitted
Make RPC use PlatformAddress
1 parent 91cac15 commit 2bf49f4

File tree

3 files changed

+33
-27
lines changed

3 files changed

+33
-27
lines changed

rpc/src/v1/impls/chain.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ use ccore::{
2020
AssetClient, BlockId, EngineInfo, ExecuteClient, MinerService, MiningBlockChainClient, RegularKey, Shard,
2121
SignedParcel, UnverifiedParcel,
2222
};
23-
use ckey::{Address, NetworkId, Public};
23+
use ckey::{NetworkId, PlatformAddress, Public};
2424
use cstate::{AssetScheme, AssetSchemeAddress, OwnedAsset};
2525
use ctypes::invoice::{ParcelInvoice, TransactionInvoice};
2626
use ctypes::parcel::Action;
2727
use ctypes::{BlockNumber, ShardId, WorldId};
28-
use primitives::{H160, H256, U256};
28+
use primitives::{H256, U256};
2929
use rlp::{DecoderError, UntrustedRlp};
3030

3131
use jsonrpc_core::Result;
@@ -135,17 +135,17 @@ where
135135
self.client.is_asset_spent(transaction_hash, index, shard_id, block_id).map_err(errors::parcel_state)
136136
}
137137

138-
fn get_nonce(&self, address: H160, block_number: Option<u64>) -> Result<Option<U256>> {
138+
fn get_nonce(&self, address: PlatformAddress, block_number: Option<u64>) -> Result<Option<U256>> {
139139
let block_id = block_number.map(BlockId::Number).unwrap_or(BlockId::Latest);
140140
Ok(self.client.nonce(&address.into(), block_id))
141141
}
142142

143-
fn get_balance(&self, address: H160, block_number: Option<u64>) -> Result<Option<U256>> {
143+
fn get_balance(&self, address: PlatformAddress, block_number: Option<u64>) -> Result<Option<U256>> {
144144
let block_id = block_number.map(BlockId::Number).unwrap_or(BlockId::Latest);
145145
Ok(self.client.balance(&address.into(), block_id.into()))
146146
}
147147

148-
fn get_regular_key(&self, address: H160, block_number: Option<u64>) -> Result<Option<Public>> {
148+
fn get_regular_key(&self, address: PlatformAddress, block_number: Option<u64>) -> Result<Option<Public>> {
149149
let block_id = block_number.map(BlockId::Number).unwrap_or(BlockId::Latest);
150150
Ok(self.client.regular_key(&address.into(), block_id.into()))
151151
}
@@ -194,23 +194,29 @@ where
194194
Ok(self.client.ready_parcels().into_iter().map(|signed| signed.into()).collect())
195195
}
196196

197-
fn get_coinbase(&self) -> Result<Option<Address>> {
197+
fn get_coinbase(&self) -> Result<Option<PlatformAddress>> {
198198
if self.miner.author().is_zero() {
199199
Ok(None)
200200
} else {
201-
Ok(Some(self.miner.author()))
201+
const VERSION: u8 = 0;
202+
let network_id = self.client.common_params().network_id;
203+
Ok(Some(PlatformAddress::create(VERSION, network_id, self.miner.author())))
202204
}
203205
}
204206

205207
fn get_network_id(&self) -> Result<NetworkId> {
206208
Ok(self.client.common_params().network_id)
207209
}
208210

209-
fn execute_change_shard_state(&self, transactions: Vec<Transaction>, sender: Address) -> Result<Vec<ChangeShard>> {
211+
fn execute_change_shard_state(
212+
&self,
213+
transactions: Vec<Transaction>,
214+
sender: PlatformAddress,
215+
) -> Result<Vec<ChangeShard>> {
210216
let transaction_types: Vec<_> = transactions.into_iter().map(From::from).collect();
211217
Ok(self
212218
.client
213-
.execute_transactions(&transaction_types, &sender)
219+
.execute_transactions(&transaction_types, &sender.into())
214220
.map_err(errors::core)?
215221
.into_iter()
216222
.map(From::from)

rpc/src/v1/traits/chain.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

17-
use ckey::{Address, NetworkId, Public};
17+
use ckey::{NetworkId, PlatformAddress, Public};
1818
use cstate::{AssetScheme, OwnedAsset};
1919
use ctypes::invoice::{ParcelInvoice, TransactionInvoice};
2020
use ctypes::{BlockNumber, ShardId, WorldId};
21-
use primitives::{H160, H256, U256};
21+
use primitives::{H256, U256};
2222

2323
use jsonrpc_core::Result;
2424

@@ -64,15 +64,15 @@ build_rpc_trait! {
6464

6565
/// Gets nonce with given account.
6666
# [rpc(name = "chain_getNonce")]
67-
fn get_nonce(&self, H160, Option<u64>) -> Result<Option<U256>>;
67+
fn get_nonce(&self, PlatformAddress, Option<u64>) -> Result<Option<U256>>;
6868

6969
/// Gets balance with given account.
7070
# [rpc(name = "chain_getBalance")]
71-
fn get_balance(&self, H160, Option<u64>) -> Result<Option<U256>>;
71+
fn get_balance(&self, PlatformAddress, Option<u64>) -> Result<Option<U256>>;
7272

7373
/// Gets regular key with given account
7474
# [rpc(name = "chain_getRegularKey")]
75-
fn get_regular_key(&self, H160, Option<u64>) -> Result<Option<Public>>;
75+
fn get_regular_key(&self, PlatformAddress, Option<u64>) -> Result<Option<Public>>;
7676

7777
/// Gets the number of shards
7878
# [rpc(name = "chain_getNumberOfShards")]
@@ -108,14 +108,14 @@ build_rpc_trait! {
108108

109109
/// Gets coinbase's account id
110110
# [rpc(name = "chain_getCoinbase")]
111-
fn get_coinbase(&self) -> Result<Option<Address>>;
111+
fn get_coinbase(&self) -> Result<Option<PlatformAddress>>;
112112

113113
/// Return the network id that is used in this chain.
114114
# [rpc(name = "chain_getNetworkId")]
115115
fn get_network_id(&self) -> Result<NetworkId>;
116116

117117
/// Execute Transactions
118118
# [rpc(name = "chain_executeTransactions")]
119-
fn execute_change_shard_state(&self, Vec<Transaction>, Address) -> Result<Vec<ChangeShard>>;
119+
fn execute_change_shard_state(&self, Vec<Transaction>, PlatformAddress) -> Result<Vec<ChangeShard>>;
120120
}
121121
}

spec/JSON-RPC.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ Response Example
276276
{
277277
"jsonrpc":"2.0",
278278
"result":{
279-
"hash":"0x56642f04d519ae3262c7ba6facf1c5b11450ebaeb7955337cfbc45420d573077",
279+
"hash":"cccqzn9jjm3j6qg69smd7cn0eup4w7z2yu9myd6c4d70x56642f04d519ae3262c7ba6facf1c5b11450ebaeb7955337cfbc45420d573077",
280280
"number":1
281281
},
282282
"id":null
@@ -663,7 +663,7 @@ Response Example
663663
Gets a nonce of an account of the given address, at state of the given blockNumber.
664664

665665
Params:
666-
1. address: `H160`
666+
1. address: `PlatformAddress`
667667
2. block number: `number` | `null`
668668

669669
Return Type: `U256`
@@ -674,7 +674,7 @@ Request Example
674674
```
675675
curl \
676676
-H 'Content-Type: application/json' \
677-
-d '{"jsonrpc": "2.0", "method": "chain_getNonce", "params": ["0xa6594b7196808d161b6fb137e781abbc251385d9", null], "id": null}' \
677+
-d '{"jsonrpc": "2.0", "method": "chain_getNonce", "params": ["cccqzn9jjm3j6qg69smd7cn0eup4w7z2yu9myd6c4d7", null], "id": null}' \
678678
localhost:8080
679679
```
680680

@@ -691,7 +691,7 @@ Response Example
691691
Gets a balance of an account of the given address, at the state of the given blockNumber.
692692

693693
Params:
694-
1. address: `H160`
694+
1. address: `PlatformAddress`
695695
2. block number: `number` | `null`
696696

697697
Return Type: `U256`
@@ -702,7 +702,7 @@ Request Example
702702
```
703703
curl \
704704
-H 'Content-Type: application/json' \
705-
-d '{"jsonrpc": "2.0", "method": "chain_getBalance", "params": ["0xa6594b7196808d161b6fb137e781abbc251385d9", null], "id": null}' \
705+
-d '{"jsonrpc": "2.0", "method": "chain_getBalance", "params": ["cccqzn9jjm3j6qg69smd7cn0eup4w7z2yu9myd6c4d7", null], "id": null}' \
706706
localhost:8080
707707
```
708708

@@ -719,7 +719,7 @@ Response Example
719719
Gets the regular key of an account of the given address, at the state of the given blockNumber.
720720

721721
Params:
722-
1. address: `H160`
722+
1. address: `PlatformAddress`
723723
2. block number: `number` | `null`
724724

725725
Return Type: `H512` - 512-bit public key
@@ -730,7 +730,7 @@ Request Example
730730
```
731731
curl \
732732
-H 'Content-Type: application/json' \
733-
-d '{"jsonrpc": "2.0", "method": "chain_getRegularKey", "params": ["0xa6594b7196808d161b6fb137e781abbc251385d9", null], "id": null}' \
733+
-d '{"jsonrpc": "2.0", "method": "chain_getRegularKey", "params": ["cccqzn9jjm3j6qg69smd7cn0eup4w7z2yu9myd6c4d7", null], "id": null}' \
734734
localhost:8080
735735
```
736736

@@ -850,7 +850,7 @@ Gets coinbase's account id.
850850

851851
Params: No parameters
852852

853-
Return Type: `H160` | `null`
853+
Return Type: `PlatformAddress` | `null`
854854

855855
Request Example
856856
```
@@ -864,7 +864,7 @@ Response Example
864864
```
865865
{
866866
"jsonrpc":"2.0",
867-
"result":"0xa6594b7196808d161b6fb137e781abbc251385d9",
867+
"result":"cccqzn9jjm3j6qg69smd7cn0eup4w7z2yu9myd6c4d7",
868868
"id":null
869869
}
870870
```
@@ -874,7 +874,7 @@ Executes the transactions and returns the current shard root and the changed sha
874874

875875
Params:
876876
1. transactions: `Transaction[]`
877-
2. sender: `H160`
877+
2. sender: `PlatformAddress`
878878

879879
Return Type: `ChangeShard[]`
880880

@@ -884,7 +884,7 @@ Request Example
884884
```
885885
curl \
886886
-H 'Content-Type: application/json' \
887-
-d '{"jsonrpc": "2.0", "method": "chain_executeTransactions", "params": [[{"type":"assetMint","data":{"networkId":"17","shardId":0,"worldId":0,"metadata":"{\"name\":\"Gold\",\"description\":\"An asset example\",\"icon_url\":\"https://gold.image/\"}","output":{"lockScriptHash":"0xf42a65ea518ba236c08b261c34af0521fa3cd1aa505e1c18980919cb8945f8f3","parameters":[],"amount":10000},"registrar":null,"nonce":0}}, {"type":"assetMint","data":{"networkId":"17","shardId":1,"worldId":0,"metadata":"{\"name\":\"Gold\",\"description\":\"An asset example\",\"icon_url\":\"https://gold.image/\"}","output":{"lockScriptHash":"0xf42a65ea518ba236c08b261c34af0521fa3cd1aa505e1c18980919cb8945f8f3","parameters":[],"amount":10000},"registrar":null,"nonce":0}}], "0xa6594b7196808d161b6fb137e781abbc251385d9"], "id": null}' \
887+
-d '{"jsonrpc": "2.0", "method": "chain_executeTransactions", "params": [[{"type":"assetMint","data":{"networkId":"17","shardId":0,"worldId":0,"metadata":"{\"name\":\"Gold\",\"description\":\"An asset example\",\"icon_url\":\"https://gold.image/\"}","output":{"lockScriptHash":"0xf42a65ea518ba236c08b261c34af0521fa3cd1aa505e1c18980919cb8945f8f3","parameters":[],"amount":10000},"registrar":null,"nonce":0}}, {"type":"assetMint","data":{"networkId":"17","shardId":1,"worldId":0,"metadata":"{\"name\":\"Gold\",\"description\":\"An asset example\",\"icon_url\":\"https://gold.image/\"}","output":{"lockScriptHash":"0xf42a65ea518ba236c08b261c34af0521fa3cd1aa505e1c18980919cb8945f8f3","parameters":[],"amount":10000},"registrar":null,"nonce":0}}], "cccqzn9jjm3j6qg69smd7cn0eup4w7z2yu9myd6c4d7"], "id": null}' \
888888
localhost:8080
889889
```
890890

0 commit comments

Comments
 (0)