Skip to content
Snippets Groups Projects
api.md 40.7 KiB
Newer Older
Androlo's avatar
Androlo committed
```
{
    field: "code"
    op: "!="
    value: "" 
}
```

We want an account filter that only includes accounts with a balance less then 1000:

```
{
    field: "balance"
    op: "<"
    value: "1000"
}
```

We want an account filter that only includes accounts with a balance higher then 0, but less then 1000.

```
{
    field: "balance"
    op: ">"
    value: "0"
}
```

```
{
    field: "balance"
    op: "<"
    value: "1000"
}
```

The field `code` is supported by accounts. It allows for the `==` and `!=` operators. The value `""` means the empty hex string.

If we wanted only non-contract accounts then we would have used the same object but changed it to `op: "=="`. 

###HTTP Queries

Androlo's avatar
Androlo committed
The structure of a normal query is: `q=field:[op]value+field2:[op2]value2+ ... `.
Androlo's avatar
Androlo committed

Androlo's avatar
Androlo committed
- `q` means it's a query.
Androlo's avatar
Androlo committed
- `+` is the filter separator.
Androlo's avatar
Androlo committed
- `field` is the field name.
Androlo's avatar
Androlo committed
- `:` is the field:relation separator.
Androlo's avatar
Androlo committed
- `op` is the relational operator, `>, <, >=, <=, ==, !=`.
Androlo's avatar
Androlo committed
- `value` is the value to compare against, e.g. `balance:>=5` or `language:==golang`. 
Androlo's avatar
Androlo committed

There is also support for [range queries](https://help.github.com/articles/search-syntax/): `A..B`, where `A` and `B` are number-strings. You may use the wildcard `*` instead of a number. The wildcard is context-sensitive; if it is put on the left-hand side it is the minimum value, and on the right-hand side it means the maximum value. Let `height` be an unsigned byte with no additional restrictions. `height:*..55` would then be the same as `height:0..55`, and `height:*..*` would be the same as `height:0..255`.
Androlo's avatar
Androlo committed

NOTE: URL encoding applies as usual. Omitting it here for clarity.

Androlo's avatar
Androlo committed
`op` will default to (`==`) if left out, meaning `balance:5` is the same as `balance:==5` 
Androlo's avatar
Androlo committed

Androlo's avatar
Androlo committed
`value` may be left out if the field accepts the empty string as input. This means if `code` is a supported string type,  `code:==` would check if the code field is empty. We could also use the inferred `==` meaning this would be equivalent: `code:`.  The system may be extended so that the empty string is automatically converted to the null-type of the underlying field, no matter what that type is. If balance is a number then `balance:` would be the same as `balance:==0` (and `balance:0`).
Androlo's avatar
Androlo committed

#####Example

We want to use the same filter as in the JSON version; one that finds all contract accounts.

Androlo's avatar
Androlo committed
`q=code:!=`
Androlo's avatar
Androlo committed

One that finds those with balance less then 1000:

Androlo's avatar
Androlo committed
`q=balance:<1000`
Androlo's avatar
Androlo committed

Androlo's avatar
Androlo committed
One that finds those where 0 <= balance <= 1000.
Androlo's avatar
Androlo committed

Androlo's avatar
Androlo committed
`q=balance:0..1000`
Androlo's avatar
Androlo committed

Androlo's avatar
Androlo committed
One that finds non-contract accounts with 0 <= balance <= 1000:
Androlo's avatar
Androlo committed

Androlo's avatar
Androlo committed
`q=balance:0..1000+code:`