Skip to content

Commit 73afaf7

Browse files
Add GetLatestBlock, GetLatestBlockHeight, GetProgram, and Get Transaction Endpoints (ProvableHQ#478)
Co-authored-by: collin <[email protected]>
1 parent a691269 commit 73afaf7

File tree

7 files changed

+224
-8
lines changed

7 files changed

+224
-8
lines changed

website/src/App.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ import React, {useState} from 'react';
33
import {Layout, Menu} from 'antd';
44
import {AccountFromPrivateKey} from "./tabs/account/AccountFromPrivateKey";
55
import {DecryptRecord} from "./tabs/record/DecryptRecord";
6-
import {GetBlockByHeight} from "./tabs/rest/GetBlockByHeight";
76
import {GetBlockByHash} from "./tabs/rest/GetBlockByHash";
7+
import {GetBlockByHeight} from "./tabs/rest/GetBlockByHeight";
8+
import {GetLatestBlock} from "./tabs/rest/GetLatestBlock";
9+
import {GetLatestBlockHeight} from "./tabs/rest/GetLatestBlockHeight";
10+
import {GetProgram} from "./tabs/rest/GetProgram";
11+
import {GetTransaction} from "./tabs/rest/GetTransaction";
12+
import {NewAccount} from "./tabs/account/NewAccount";
813
import {SignMessage} from "./tabs/account/SignMessage";
914
import {VerifyMessage} from "./tabs/account/VerifyMessage";
10-
import {NewAccount} from "./tabs/account/NewAccount";
1115

1216
const {Header, Content, Footer} = Layout;
1317

@@ -46,9 +50,17 @@ function App() {
4650
{
4751
menuIndex === 2 &&
4852
<>
53+
<GetLatestBlockHeight/>
54+
<br/>
55+
<GetLatestBlock/>
56+
<br/>
4957
<GetBlockByHeight/>
5058
<br/>
5159
<GetBlockByHash/>
60+
<br/>
61+
<GetProgram/>
62+
<br/>
63+
<GetTransaction/>
5264
</>
5365
}
5466
</Content>

website/src/tabs/rest/GetBlockByHash.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ import axios from "axios";
44
import {CopyButton} from "../../components/CopyButton";
55

66
export const GetBlockByHash = () => {
7-
const [hash, setHash] = useState(null);
87
const [blockByHash, setBlockByHash] = useState(null);
98

109
const onChange = (event) => {
11-
setHash(null);
1210
try {
13-
setHash(event.target.value);
1411
tryRequest(event.target.value);
1512
} catch (error) {
1613
console.error(error);

website/src/tabs/rest/GetBlockByHeight.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ import axios from "axios";
44
import {CopyButton} from "../../components/CopyButton";
55

66
export const GetBlockByHeight = () => {
7-
const [height, setHeight] = useState(null);
87
const [blockByHeight, setBlockByHeight] = useState(null);
98

109
const onChange = (event) => {
11-
setHeight(null);
1210
try {
13-
setHeight(event.target.value);
1411
tryRequest(event.target.value);
1512
} catch (error) {
1613
console.error(error);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React, { useState } from "react";
2+
import {Button, Card, Col, Divider, Form, Input, Row} from "antd";
3+
import axios from "axios";
4+
import { CopyButton } from "../../components/CopyButton";
5+
6+
export const GetLatestBlock = () => {
7+
const [latestBlock, setLatestBlock] = useState(null);
8+
9+
const tryRequest = () => {
10+
setLatestBlock(null);
11+
try {
12+
axios
13+
.get(`https://vm.aleo.org/api/testnet3/latest/block`)
14+
.then((response) =>
15+
setLatestBlock(JSON.stringify(response.data, null, 2))
16+
);
17+
} catch (error) {
18+
console.error(error);
19+
}
20+
};
21+
22+
const layout = { labelCol: { span: 3 }, wrapperCol: { span: 21 } };
23+
24+
const latestBlockString = () =>
25+
latestBlock !== null ? latestBlock.toString() : "";
26+
27+
return <Card title="Get Latest Block" style={{width: "100%", borderRadius: "20px"}} bordered={false}>
28+
<Row justify="center">
29+
<Col><Button type="primary" shape="round" size="middle" onClick={tryRequest}
30+
>Get Latest Block</Button></Col>
31+
</Row>
32+
{
33+
(latestBlock !== null) ?
34+
<Form {...layout}>
35+
<Divider/>
36+
<Form.Item label="Block" colon={false}>
37+
<Input.TextArea size="large" rows={15} placeholder="Block" value={latestBlockString()}
38+
addonAfter={<CopyButton data={latestBlockString()} style={{borderRadius: '20px'}}/>}
39+
disabled/>
40+
</Form.Item>
41+
</Form>
42+
: null
43+
}
44+
</Card>
45+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React, { useState } from "react";
2+
import {Button, Card, Col, Divider, Form, Input, Row} from "antd";
3+
import axios from "axios";
4+
import { CopyButton } from "../../components/CopyButton";
5+
6+
export const GetLatestBlockHeight = () => {
7+
const [latestHeight, setLatestHeight] = useState(null);
8+
9+
const tryRequest = () => {
10+
setLatestHeight(null);
11+
try {
12+
axios
13+
.get(`https://vm.aleo.org/api/testnet3/latest/height`)
14+
.then((response) =>
15+
setLatestHeight(JSON.stringify(response.data, null, 2))
16+
);
17+
} catch (error) {
18+
console.error(error);
19+
}
20+
};
21+
22+
const layout = {labelCol: {span: 3}, wrapperCol: {span: 21}};
23+
24+
const latestHeightString = () =>
25+
latestHeight !== null ? latestHeight.toString() : "";
26+
27+
return <Card title="Get Block Height" style={{width: "100%", borderRadius: "20px"}} bordered={false}>
28+
<Row justify="center">
29+
<Col><Button type="primary" shape="round" size="middle" onClick={tryRequest}
30+
>Get Latest Block Height</Button></Col>
31+
</Row>
32+
{
33+
(latestHeight !== null) ?
34+
<Form {...layout}>
35+
<Divider/>
36+
<Form.Item label="Block" colon={false}>
37+
<Input.TextArea size="large" rows={1} placeholder="Block" value={latestHeightString()}
38+
addonAfter={<CopyButton data={latestHeightString()} style={{borderRadius: '20px'}}/>}
39+
disabled/>
40+
</Form.Item>
41+
</Form>
42+
: null
43+
}
44+
</Card>
45+
}

website/src/tabs/rest/GetProgram.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React, { useState } from "react";
2+
import {Button, Card, Col, Divider, Form, Input, Row} from "antd";
3+
import axios from "axios";
4+
import { CopyButton } from "../../components/CopyButton";
5+
6+
export const GetProgram = () => {
7+
const [program, setProgram] = useState(null);
8+
const [programName, setProgramName] = useState(null);
9+
10+
const onChange = (event) => {
11+
try {
12+
tryRequest(event.target.value);
13+
} catch (error) {
14+
console.error(error);
15+
}
16+
};
17+
18+
const tryRequest = (id) => {
19+
setProgramName(id);
20+
try {
21+
if (id) {
22+
axios
23+
.get(`https://vm.aleo.org/api/testnet3/program/${id}`)
24+
.then((response) =>
25+
setProgram(JSON.stringify(response.data, null, 10))
26+
);
27+
}
28+
} catch (error) {
29+
console.error(error);
30+
}
31+
};
32+
33+
34+
const layout = { labelCol: { span: 3 }, wrapperCol: { span: 21 } };
35+
const programString = () => program !== null ? program : "";
36+
const programNameString = () => programName !== null ? programName : "";
37+
38+
return <Card title="Get Program" style={{width: "100%", borderRadius: "20px"}} bordered={false}>
39+
<Form {...layout}>
40+
<Form.Item label="Program Name" colon={false}>
41+
<Input name="id" size="large" placeholder="Program Name" allowClear onChange={onChange}
42+
value={programNameString()} style={{borderRadius: '20px'}}/>
43+
</Form.Item>
44+
</Form>
45+
{
46+
(program !== null) ?
47+
<Form {...layout}>
48+
<Divider/>
49+
<Form.Item label="Program" colon={false}>
50+
<Input.TextArea size="large" rows={15} placeholder="Program" style={{whiteSpace: 'pre-wrap', overflowWrap: 'break-word'}}
51+
value={programString()}
52+
addonAfter={<CopyButton data={programString()}
53+
style={{borderRadius: '20px'}}/>} disabled/>
54+
</Form.Item>
55+
</Form>
56+
:
57+
<Row justify="center">
58+
<Col><Button type="primary" shape="round" size="middle" onClick={() => {tryRequest("credits.aleo")}}
59+
>Get credits.aleo</Button></Col>
60+
</Row>
61+
}
62+
</Card>
63+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import React, {useState} from "react";
2+
import {Card, Divider, Form, Input} from "antd";
3+
import axios from "axios";
4+
import {CopyButton} from "../../components/CopyButton";
5+
6+
export const GetTransaction = () => {
7+
const [transaction, setTransaction] = useState(null);
8+
9+
const onChange = (event) => {
10+
try {
11+
tryRequest(event.target.value);
12+
} catch (error) {
13+
console.error(error);
14+
}
15+
};
16+
17+
const tryRequest = (id) => {
18+
setTransaction(null);
19+
try {
20+
if (id) {
21+
axios
22+
.get(`https://vm.aleo.org/api/testnet3/transaction/${id}`)
23+
.then((response) =>
24+
setTransaction(JSON.stringify(response.data, null, 2))
25+
);
26+
}
27+
} catch (error) {
28+
console.error(error);
29+
}
30+
};
31+
32+
const layout = {labelCol: {span: 3}, wrapperCol: {span: 21}};
33+
34+
const transactionString = () =>
35+
transaction !== null ? transaction.toString() : "";
36+
37+
return <Card title="Get Transaction" style={{width: "100%", borderRadius: "20px"}} bordered={false}>
38+
<Form {...layout}>
39+
<Form.Item label="Transaction ID" colon={false}>
40+
<Input name="id" size="large" placeholder="Transaction ID" allowClear onChange={onChange}
41+
style={{borderRadius: '20px'}}/>
42+
</Form.Item>
43+
</Form>
44+
{
45+
(transaction !== null) ?
46+
<Form {...layout}>
47+
<Divider/>
48+
<Form.Item label="Transaction" colon={false}>
49+
<Input.TextArea size="large" rows={15} placeholder="Block" value={transactionString()}
50+
addonAfter={<CopyButton data={transactionString()}
51+
style={{borderRadius: '20px'}}/>} disabled/>
52+
</Form.Item>
53+
</Form>
54+
: null
55+
}
56+
</Card>
57+
}

0 commit comments

Comments
 (0)