mirror of
https://github.com/Qortal/qortal.git
synced 2025-04-23 19:37:51 +00:00
Added "FETCH_BLOCK" and "FETCH_BLOCK_RANGE" Q-Apps actions.
This commit is contained in:
parent
03a54691a1
commit
ca80fd5f9c
28
Q-Apps.md
28
Q-Apps.md
@ -73,6 +73,8 @@ Here is a list of currently supported actions:
|
|||||||
- GET_AT
|
- GET_AT
|
||||||
- GET_AT_DATA
|
- GET_AT_DATA
|
||||||
- LIST_ATS
|
- LIST_ATS
|
||||||
|
- FETCH_BLOCK
|
||||||
|
- FETCH_BLOCK_RANGE
|
||||||
|
|
||||||
More functionality will be added in the future.
|
More functionality will be added in the future.
|
||||||
|
|
||||||
@ -345,6 +347,32 @@ let res = await qortalRequest({
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Fetch block by signature
|
||||||
|
```
|
||||||
|
let res = await qortalRequest({
|
||||||
|
action: "FETCH_BLOCK",
|
||||||
|
signature: "875yGFUy1zHV2hmxNWzrhtn9S1zkeD7SQppwdXFysvTXrankCHCz4iyAUgCBM3GjvibbnyRQpriuy1cyu953U1u5uQdzuH3QjQivi9UVwz86z1Akn17MGd5Z5STjpDT7248K6vzMamuqDei57Znonr8GGgn8yyyABn35CbZUCeAuXju"
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Fetch block by height
|
||||||
|
```
|
||||||
|
let res = await qortalRequest({
|
||||||
|
action: "FETCH_BLOCK",
|
||||||
|
height: "1139850"
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Fetch a range of blocks
|
||||||
|
```
|
||||||
|
let res = await qortalRequest({
|
||||||
|
action: "FETCH_BLOCK_RANGE",
|
||||||
|
height: "1139800",
|
||||||
|
count: 20,
|
||||||
|
reverse: false
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Sample App
|
## Sample App
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ import org.qortal.data.account.AccountData;
|
|||||||
import org.qortal.data.arbitrary.ArbitraryResourceInfo;
|
import org.qortal.data.arbitrary.ArbitraryResourceInfo;
|
||||||
import org.qortal.data.arbitrary.ArbitraryResourceStatus;
|
import org.qortal.data.arbitrary.ArbitraryResourceStatus;
|
||||||
import org.qortal.data.at.ATData;
|
import org.qortal.data.at.ATData;
|
||||||
|
import org.qortal.data.block.BlockData;
|
||||||
import org.qortal.data.chat.ChatMessage;
|
import org.qortal.data.chat.ChatMessage;
|
||||||
import org.qortal.data.group.GroupData;
|
import org.qortal.data.group.GroupData;
|
||||||
import org.qortal.data.naming.NameData;
|
import org.qortal.data.naming.NameData;
|
||||||
@ -179,6 +180,30 @@ public class AppsResource {
|
|||||||
return atResource.getByFunctionality(codeHash58, isExecutable, limit, offset, reverse);
|
return atResource.getByFunctionality(codeHash58, isExecutable, limit, offset, reverse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/block")
|
||||||
|
@Hidden // For internal Q-App API use only
|
||||||
|
public BlockData fetchBlockByHeight(@QueryParam("signature") String signature58, @QueryParam("includeOnlineSignatures") Boolean includeOnlineSignatures) {
|
||||||
|
BlocksResource blocksResource = (BlocksResource) buildResource(BlocksResource.class, request, response, context);
|
||||||
|
return blocksResource.getBlock(signature58, includeOnlineSignatures);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/block/byheight")
|
||||||
|
@Hidden // For internal Q-App API use only
|
||||||
|
public BlockData fetchBlockByHeight(@QueryParam("height") int height, @QueryParam("includeOnlineSignatures") Boolean includeOnlineSignatures) {
|
||||||
|
BlocksResource blocksResource = (BlocksResource) buildResource(BlocksResource.class, request, response, context);
|
||||||
|
return blocksResource.getByHeight(height, includeOnlineSignatures);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/block/range")
|
||||||
|
@Hidden // For internal Q-App API use only
|
||||||
|
public List<BlockData> getBlockRange(@QueryParam("height") int height, @Parameter(ref = "count") @QueryParam("count") int count, @Parameter(ref = "reverse") @QueryParam("reverse") Boolean reverse, @QueryParam("includeOnlineSignatures") Boolean includeOnlineSignatures) {
|
||||||
|
BlocksResource blocksResource = (BlocksResource) buildResource(BlocksResource.class, request, response, context);
|
||||||
|
return blocksResource.getBlockRange(height, count, reverse, includeOnlineSignatures);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Object buildResource(Class<?> resourceClass, HttpServletRequest request, HttpServletResponse response, ServletContext context) {
|
public static Object buildResource(Class<?> resourceClass, HttpServletRequest request, HttpServletResponse response, ServletContext context) {
|
||||||
try {
|
try {
|
||||||
|
@ -155,6 +155,28 @@ window.addEventListener("message", (event) => {
|
|||||||
response = httpGet(url);
|
response = httpGet(url);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "FETCH_BLOCK":
|
||||||
|
if (data.signature != null) {
|
||||||
|
url = "/apps/block?";
|
||||||
|
url = url.concat("&signature=" + data.signature);
|
||||||
|
}
|
||||||
|
else if (data.height != null) {
|
||||||
|
url = "/apps/block/byheight?";
|
||||||
|
url = url.concat("&height=" + data.height);
|
||||||
|
}
|
||||||
|
if (data.includeOnlineSignatures != null) url = url.concat("&includeOnlineSignatures=" + data.includeOnlineSignatures);
|
||||||
|
response = httpGet(url);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "FETCH_BLOCK_RANGE":
|
||||||
|
url = "/apps/block/range?";
|
||||||
|
if (data.height != null) url = url.concat("&height=" + data.height);
|
||||||
|
if (data.count != null) url = url.concat("&count=" + data.count);
|
||||||
|
if (data.reverse != null) url = url.concat("&reverse=" + data.reverse);
|
||||||
|
if (data.includeOnlineSignatures != null) url = url.concat("&includeOnlineSignatures=" + data.includeOnlineSignatures);
|
||||||
|
response = httpGet(url);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Pass to parent (UI), in case they can fulfil this request
|
// Pass to parent (UI), in case they can fulfil this request
|
||||||
event.data.requestedHandler = "UI";
|
event.data.requestedHandler = "UI";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user