Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
merge conflicts to master
Browse files Browse the repository at this point in the history
  • Loading branch information
Cody Douglass committed Apr 1, 2019
2 parents d100296 + 41bb99b commit a2c7836
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 22 deletions.
50 changes: 28 additions & 22 deletions docs/4.-Reading blockchain-Examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ Get the first 10 token balances of account _testacc_.
```javascript
const resp = await rpc.get_table_rows({
json: true, // Get the response as json
code: 'eosio.token', // Contract that we target
scope: 'testacc' // Account that owns the data
table: 'accounts' // Table name
limit: 10, // maximum number of rows that we want to get
code: 'eosio.token', // Contract that we target
scope: 'testacc' // Account that owns the data
table: 'accounts' // Table name
limit: 10, // Maximum number of rows that we want to get
reverse = false, // Optional: Get reversed data
show_payer = false, // Optional: Show ram payer
});

console.log(resp.rows);
```
Output:
Output:

```json
{
Expand All @@ -42,15 +44,17 @@ Output:
```javascript
const resp = await rpc.get_table_rows({
json: true, // Get the response as json
code: 'contract', // Contract that we target
scope: 'contract' // Account that owns the data
table: 'profiles' // Table name
lower_bound: 'testacc' // Table primary key value
code: 'contract', // Contract that we target
scope: 'contract' // Account that owns the data
table: 'profiles' // Table name
lower_bound: 'testacc' // Table primary key value
limit: 1, // Here we limit to 1 to get only the
reverse = false, // Optional: Get reversed data
show_payer = false, // Optional: Show ram payer
});
console.log(resp.rows);
```
Output:
Output:

```json
{
Expand All @@ -64,21 +68,23 @@ Output:
}
```

### Get one row by secondary index
### Get one row by secondary index

```javascript
const resp = await rpc.get_table_rows({
json: true, // Get the response as json
code: 'contract', // Contract that we target
scope: 'contract' // Account that owns the data
table: 'profiles' // Table name
table_key: 'age' // Table secondaray key name
lower_bound: 21 // Table secondary key value
limit: 1, // Here we limit to 1 to get only the
code: 'contract', // Contract that we target
scope: 'contract' // Account that owns the data
table: 'profiles' // Table name
table_key: 'age' // Table secondaray key name
lower_bound: 21 // Table secondary key value
limit: 1, // Here we limit to 1 to get only row
reverse = false, // Optional: Get reversed data
show_payer = false, // Optional: Show ram payer
});
console.log(resp.rows);
```
Output:
Output:

```json
{
Expand All @@ -97,7 +103,7 @@ Output:
```javascript
console.log(await rpc.get_currency_balance('eosio.token', 'testacc', 'HAK'));
```
Output:
Output:

```json
[ "1000000000.0000 HAK" ]
Expand All @@ -108,7 +114,7 @@ Output:
```javascript
console.log(await rpc.get_account('testacc'));
```
Output:
Output:

```json
{ "account_name": "testacc",
Expand All @@ -123,7 +129,7 @@ Output:
"net_limit": { "used": -1, "available": -1, "max": -1 },
"cpu_limit": { "used": -1, "available": -1, "max": -1 },
"ram_usage": 2724,
"permissions":
"permissions":
[ { "perm_name": "active", "parent": "owner", "required_auth": [] },
{ "perm_name": "owner", "parent": "", "required_auth": [] } ],
"total_resources": null,
Expand All @@ -137,7 +143,7 @@ Output:
```javascript
console.log(await rpc.get_block(1));
```
Output:
Output:

```json
{ "timestamp": "2018-06-01T12:00:00.000",
Expand Down
4 changes: 4 additions & 0 deletions src/eosjs-jsonrpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ export class JsonRpc implements AuthorityProvider, AbiProvider {
index_position = 1,
key_type = '',
limit = 10,
reverse = false,
show_payer = false,
}: any): Promise<any> {
return await this.fetch(
'/v1/chain/get_table_rows', {
Expand All @@ -150,6 +152,8 @@ export class JsonRpc implements AuthorityProvider, AbiProvider {
index_position,
key_type,
limit,
reverse,
show_payer,
});
}

Expand Down
8 changes: 8 additions & 0 deletions src/tests/eosjs-jsonrpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ describe('JSON RPC', () => {
const indexPosition = 1;
const keyType = 'str';
const expReturn = { data: '12345' };
const reverse = false;
const showPayer = false;
const callParams = {
json,
code,
Expand All @@ -365,6 +367,8 @@ describe('JSON RPC', () => {
index_position: indexPosition,
key_type: keyType,
limit,
reverse,
show_payer: showPayer,
};
const expParams = {
body: JSON.stringify(callParams),
Expand All @@ -391,6 +395,8 @@ describe('JSON RPC', () => {
const limit = 10;
const indexPosition = 1;
const keyType = '';
const reverse = false;
const showPayer = false;
const expReturn = { data: '12345' };
const callParams = {
code,
Expand All @@ -409,6 +415,8 @@ describe('JSON RPC', () => {
index_position: indexPosition,
key_type: keyType,
limit,
reverse,
show_payer: showPayer,
}),
method: 'POST',
};
Expand Down

0 comments on commit a2c7836

Please sign in to comment.