Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add database api and account api to json_rpc_api.md file #1227

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
192 changes: 192 additions & 0 deletions JSON_RPC_API.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,196 @@
# AIN Blockchain JSON-RPC API

## Database API

### ain_get

Returns the value, write rule, owner rule, or function at the given path in the global state tree.

**Parameters**


**Returns**

The Array of data/rule/owner data/function hash at each path. The order will be preserved, and if there isn't data present at the path, `null` will be at the path's index.

**Example**

Request
```
curl -X POST --data
'{
"jsonrpc":"2.0",
"id":1,
"method":"ain_get",
"params":{
"type": "GET"
"op_list": [
{"ref": "afan/user123/balance","type": "GET_VALUE"},
{"ref": "afan/$userId","type": "GET_RULE"}
]
}
}'
```

Response
```
{
"jsonrpc":"2.0",
"id":1,
"result":[1000, {".rule": {"write": "'$userId' === auth"}}]
}
```

---

## Account API

### ain_getBalance

Returns the balance of an account.

**Parameters**

An object with a property:

- address: `String` - address of the account to get the balance of.

**Returns**

`Number` - The balance.

**Example**

Request
```
curl -X POST --data
'{
"jsonrpc":"2.0",
"id":1,
"method":"ain_getBalance",
"params":{"address":"0xc94770007dda54cF92009BFF0dE90c06F603a09f"}
}'
```

Response
```
{
"jsonrpc":"2.0",
"id":1,
"result":98347
}
```

### ain_getConsensusStakeAmount

Returns the amount of AIN the account (node) is staking for participating in the consensus protocol.

**Parameters**[](#parameters-1)

An object with a property:

- address: `String` - address of the account.

**Returns**

`Number` - The amount at stake.

**Example**

Request
```
curl -X POST --data
'{
"jsonrpc":"2.0",
"id":1,
"method":"ain_getConsensusStakeAmount",
"params":{"address":"0xc94770007dda54cF92009BFF0dE90c06F603a09f"}
}'
```

Response
```
{
"jsonrpc":"2.0",
"id":1,
"result":1000
}
```

### ain_getNonce

Returns the nonce (= number of transactions an address has sent) of an address.

**Parameters**

An object with a property:

- address: `String` - address of the account to get the transaction count of

**Returns**

`Number` - The nonce.

**Example**

Request
```
curl -X POST --data
'{
"jsonrpc":"2.0",
"id":1,
"method":"ain_getNonce",
"params":{"address":"0xc94770007dda54cF92009BFF0dE90c06F603a09f"}
}'
```

Response
```
{
"jsonrpc":"2.0",
"id":1,
"result":10
}
```

### ain_isValidator

Returns whether the node is currently a validator or not.

**Parameters**

An object with a property:

- address: `String` - address of the account to check if it's currently in the validator set

**Returns**

`Boolean` - Whether the node is a validator or not.

**Example**

Request
```
curl -X POST --data
'{
"jsonrpc":"2.0",
"id":1,
"method":"ain_isValidator",
"params":{"address":"0xc94770007dda54cF92009BFF0dE90c06F603a09f"}
}'
```

Response
```
{
"jsonrpc":"2.0",
"id":1,
"result":true
}
```

---

## Transaction API

### ain_getPendingTransactions
Expand Down Expand Up @@ -937,3 +1128,4 @@ Response
}
```

---
Loading