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

Commit

Permalink
Merge pull request #1656 from bandprotocol/add-new-copy-proof
Browse files Browse the repository at this point in the history
  • Loading branch information
Sawit Trisirisatayawong authored Jun 10, 2020
2 parents 7afe3bd + f0d2feb commit 57218bf
Show file tree
Hide file tree
Showing 20 changed files with 327 additions and 111 deletions.
8 changes: 7 additions & 1 deletion scan/src/bindings/JsBuffer.re
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ type t;

[@bs.val] external from: array(int) => t = "Buffer.from";

[@bs.val] external byteLength: t => int = "Buffer.byteLength";

[@bs.val] external concat: array(t) => t = "Buffer.concat";

[@bs.val] external _from: (string, string) => t = "Buffer.from";

let fromHex = hexstr => hexstr->HexUtils.normalizeHexString->_from("hex");

let fromUTF8 = utf8 => _from(utf8, "utf-8");

let fromBase64 = hexstr => _from(hexstr, "base64");

[@bs.send] external _toString: (t, string) => string = "toString";
Expand All @@ -22,4 +29,3 @@ let arrayToHex = arr => arr->from->toHex;
let hexToArray = hexstr => hexstr->fromHex->toArray;
let arrayToBase64 = arr => arr->from->toBase64;
let base64ToArray = base64str => base64str->fromBase64->toArray;

4 changes: 2 additions & 2 deletions scan/src/components/Packet.re
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ let make = (~packet: IBCSub.packet_t, ~oracleScriptID: ID.OracleScript.t) => {
<div className=Styles.hFlex>
<Text value="CALLDATA" size=Text.Sm weight=Text.Thin spacing={Text.Em(0.06)} />
<HSpacing size=Spacing.md />
<CopyButton data={request.calldata} />
<CopyButton data={request.calldata} title="Copy as bytes" />
</div>;
switch (outputKVsOpt) {
| Some(_) => calldataHeadRender
Expand Down Expand Up @@ -140,7 +140,7 @@ let make = (~packet: IBCSub.packet_t, ~oracleScriptID: ID.OracleScript.t) => {
<div className=Styles.hFlex>
<Text value="RESULT" size=Text.Sm weight=Text.Thin spacing={Text.Em(0.06)} />
<HSpacing size=Spacing.md />
<CopyButton data=result />
<CopyButton data=result title="Copy as bytes" />
</div>;
switch (outputKVsOpt) {
| Some(_) => resultHeadRender
Expand Down
29 changes: 14 additions & 15 deletions scan/src/components/RequestProof.re
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module Styles = {
};

[@react.component]
let make = (~requestID: ID.Request.t) => {
let make = (~requestID: ID.Request.t, ~requestOpt: option(RequestSub.t)) => {
let (proofOpt, reload) = ProofHook.get(requestID);
let (showProof, setShowProof) = React.useState(_ => false);

Expand Down Expand Up @@ -62,27 +62,26 @@ let make = (~requestID: ID.Request.t) => {
color=Colors.gray6
/>
</Col>
<Col size=1.>
<div className={Styles.withWidth(700)}>
<Text
value={proof.evmProofBytes |> JsBuffer.toHex}
weight=Text.Medium
color=Colors.gray7
block=true
code=true
ellipsis=true
/>
</div>
</Col>
</div>
<div className={Styles.topicContainer(20)}>
<Col size=1.> React.null </Col>
<Col size=1.>
<div className={Styles.withWidth(700)}>
<div className=Styles.hFlex>
<ShowProofButton showProof setShowProof />
<HSpacing size=Spacing.md />
<CopyButton data={proof.evmProofBytes} />
<CopyButton data={proof.evmProofBytes} title="Copy EVM proof" width=115 />
<HSpacing size=Spacing.md />
<CopyButton
data={
switch (requestOpt) {
| Some({result: Some(_)}) =>
NonEVMProof.Request(requestOpt->Belt_Option.getExn)->NonEVMProof.createProof
| _ => "" |> JsBuffer.fromHex
}
}
title="Copy non-EVM proof"
width=130
/>
<HSpacing size=Spacing.md />
<ExtLinkButton link="https://docs.bandchain.org/" description="What is proof ?" />
</div>
Expand Down
2 changes: 1 addition & 1 deletion scan/src/components/TxIndexPageTable.re
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ let renderRequest = (request: TxSub.Msg.Request.t) => {
<div className=Styles.hFlex>
<Text value="CALLDATA" size=Text.Sm weight=Text.Thin spacing={Text.Em(0.06)} />
<HSpacing size=Spacing.md />
<CopyButton data={request.calldata} />
<CopyButton data={request.calldata} title="Copy as bytes" />
</div>
<VSpacing size=Spacing.md />
{switch (calldataKVsOpt) {
Expand Down
12 changes: 7 additions & 5 deletions scan/src/components/buttons/CopyButton.re
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module Styles = {
open Css;

let button =
let button = w =>
style([
backgroundColor(Colors.blue1),
padding2(~h=`px(8), ~v=`px(4)),
display(`flex),
width(`px(103)),
width(`px(w)),
borderRadius(`px(6)),
cursor(`pointer),
boxShadow(Shadow.box(~x=`zero, ~y=`px(2), ~blur=`px(4), rgba(20, 32, 184, 0.2))),
Expand All @@ -16,10 +16,12 @@ module Styles = {
};

[@react.component]
let make = (~data) => {
<div className=Styles.button onClick={_ => {Copy.copy(data |> JsBuffer.toHex(~with0x=false))}}>
let make = (~data, ~title, ~width=105) => {
<div
className={Styles.button(width)}
onClick={_ => {Copy.copy(data |> JsBuffer.toHex(~with0x=false))}}>
<img src=Images.copy className=Styles.withHeight />
<HSpacing size=Spacing.sm />
<Text value="Copy as bytes" size=Text.Sm block=true color=Colors.bandBlue nowrap=true />
<Text value=title size=Text.Sm block=true color=Colors.bandBlue nowrap=true />
</div>;
};
4 changes: 2 additions & 2 deletions scan/src/components/data-source/DataSourceRequestTable.re
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ let make = (~dataSourceID: ID.DataSource.t) =>
</THead>
{requests
->Belt_Array.map(
({id, oracleScriptID, oracleScriptName, timestamp, blockHeight, txHash}) => {
({id, oracleScriptID, oracleScriptName, txTimestamp, blockHeight, txHash}) => {
<TBody key={txHash |> Hash.toHex(~upper=true)}>
<Row>
<Col> <HSpacing size=Spacing.lg /> </Col>
Expand All @@ -114,7 +114,7 @@ let make = (~dataSourceID: ID.DataSource.t) =>
</Row>
</Col>
<Col size=2.5>
<Timestamp time=timestamp size=Text.Md weight=Text.Regular code=true />
<Timestamp time=txTimestamp size=Text.Md weight=Text.Regular code=true />
</Col>
<Col size=1.0> <TypeID.Block id=blockHeight /> </Col>
<Col size=2.7> <TxLink txHash width=230 weight=Text.Medium /> </Col>
Expand Down
37 changes: 15 additions & 22 deletions scan/src/components/oracle-script/OracleScriptExecuteProof.re
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Styles = {
};

[@react.component]
let make = (~id: ID.Request.t) => {
let make = (~id: ID.Request.t, ~requestOpt: option(RequestSub.Mini.t)) => {
let (proofOpt, reload) = ProofHook.get(id);

React.useEffect1(
Expand Down Expand Up @@ -47,33 +47,26 @@ let make = (~id: ID.Request.t) => {
height={Text.Px(15)}
/>
</div>
{switch (proofOpt) {
| Some(proof) =>
<div className={Styles.vFlex(`px(660), `auto)}>
<Text
value={proof.evmProofBytes |> JsBuffer.toHex}
height={Text.Px(15)}
code=true
ellipsis=true
{switch (proofOpt, requestOpt) {
| (Some(proof), Some({result: Some(_)})) =>
<div className={Styles.hFlex(`auto)}>
<CopyButton data={proof.evmProofBytes} title="Copy EVM proof" width=115 />
<HSpacing size=Spacing.md />
<CopyButton
data={
NonEVMProof.RequestMini(requestOpt->Belt_Option.getExn)->NonEVMProof.createProof
}
title="Copy non-EVM proof"
width=130
/>
<HSpacing size=Spacing.lg />
<ExtLinkButton link="https://docs.bandchain.org/" description="What is proof ?" />
</div>
| None =>
| _ =>
<div className={Styles.withWH(`percent(100.), `auto)}>
<img src=Images.loadingCircles className={Styles.withWH(`px(104), `px(30))} />
</div>
}}
</div>
<VSpacing size=Spacing.md />
{switch (proofOpt) {
| Some(proof) =>
<div className={Styles.hFlex(`auto)}>
<HSpacing size=Spacing.lg />
<div className={Styles.vFlex(`px(220), `auto)} />
<CopyButton data={proof.evmProofBytes} />
<HSpacing size=Spacing.lg />
<ExtLinkButton link="https://docs.bandchain.org/" description="What is proof ?" />
</div>
| None => React.null
}}
</>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ let make = (~txResponse: TxCreator.tx_response_t, ~schema: string) =>
</div>
</div>
<VSpacing size=Spacing.lg />
<OracleScriptExecuteProof id />
<OracleScriptExecuteProof id requestOpt />
</>;
| Some(request) =>
<div className={Styles.hFlex(`auto)}>
Expand Down
4 changes: 2 additions & 2 deletions scan/src/components/oracle-script/OracleScriptRequestTable.re
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ let make = (~oracleScriptID: ID.OracleScript.t) =>
</Row>
</THead>
{requests
->Belt_Array.map(({id, requester, timestamp, blockHeight, txHash}) => {
->Belt_Array.map(({id, requester, txTimestamp, blockHeight, txHash}) => {
<TBody key={txHash |> Hash.toHex(~upper=true)}>
<Row>
<Col> <HSpacing size=Spacing.lg /> </Col>
Expand All @@ -110,7 +110,7 @@ let make = (~oracleScriptID: ID.OracleScript.t) =>
</div>
</Col>
<Col size=2.2>
<Timestamp time=timestamp size=Text.Md weight=Text.Regular code=true />
<Timestamp time=txTimestamp size=Text.Md weight=Text.Regular code=true />
</Col>
<Col size=1.26> <TypeID.Block id=blockHeight /> </Col>
<Col size=2.8> <TxLink txHash width=230 weight=Text.Medium /> </Col>
Expand Down
6 changes: 3 additions & 3 deletions scan/src/pages/RequestIndexPage.re
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ let make = (~reqID) =>
color=Colors.gray6
/>
<HSpacing size=Spacing.md />
<CopyButton data={request.calldata} />
<CopyButton data={request.calldata} title="Copy as bytes" />
</div>
</Col>
</div>
Expand Down Expand Up @@ -272,7 +272,7 @@ let make = (~reqID) =>
color=Colors.gray6
/>
<HSpacing size=Spacing.md />
<CopyButton data=result />
<CopyButton data=result title="Copy as bytes" />
</div>
</Col>
</div>
Expand All @@ -292,7 +292,7 @@ let make = (~reqID) =>
}}
{numReport >= request.minCount
? {
<RequestProof requestID={request.id} />;
<RequestProof requestID={request.id} requestOpt={Some(request)} />;
}
: React.null}
<VSpacing size=Spacing.xl />
Expand Down
6 changes: 3 additions & 3 deletions scan/src/subscriptions/BlockSub.re
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module MultiConfig = [%graphql
operatorAddress: operator_address @bsDecoder(fn: "Address.fromBech32")
moniker
}
timestamp @bsDecoder(fn: "GraphQLParser.time")
timestamp @bsDecoder(fn: "GraphQLParser.timeMS")
transactions_aggregate @bsRecord {
aggregate @bsRecord {
count @bsDecoder(fn: "Belt_Option.getExn")
Expand All @@ -65,7 +65,7 @@ module MultiConsensusAddressConfig = [%graphql
operatorAddress: operator_address @bsDecoder(fn: "Address.fromBech32")
moniker
}
timestamp @bsDecoder(fn: "GraphQLParser.time")
timestamp @bsDecoder(fn: "GraphQLParser.timeMS")
transactions_aggregate @bsRecord {
aggregate @bsRecord {
count @bsDecoder(fn: "Belt_Option.getExn")
Expand All @@ -87,7 +87,7 @@ module SingleConfig = [%graphql
operatorAddress: operator_address @bsDecoder(fn: "Address.fromBech32")
moniker
}
timestamp @bsDecoder(fn: "GraphQLParser.time")
timestamp @bsDecoder(fn: "GraphQLParser.timeMS")
transactions_aggregate @bsRecord {
aggregate @bsRecord {
count @bsDecoder(fn: "Belt_Option.getExn")
Expand Down
2 changes: 1 addition & 1 deletion scan/src/subscriptions/DataSourceRevisionSub.re
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module RevisionsConfig = [%graphql
transaction @bsRecord {
txHash: tx_hash @bsDecoder(fn: "GraphQLParser.hash")
blockHeight: block_height @bsDecoder(fn: "ID.Block.fromJson")
timestamp @bsDecoder(fn: "GraphQLParser.time")
timestamp @bsDecoder(fn: "GraphQLParser.timeMS")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions scan/src/subscriptions/DataSourceSub.re
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module MultiConfig = [%graphql
name
description
executable @bsDecoder(fn: "GraphQLParser.buffer")
timestamp: last_updated @bsDecoder(fn: "GraphQLParser.time")
timestamp: last_updated @bsDecoder(fn: "GraphQLParser.timeMS")
}
}
|}
Expand All @@ -31,7 +31,7 @@ module SingleConfig = [%graphql
name
description
executable @bsDecoder(fn: "GraphQLParser.buffer")
timestamp: last_updated @bsDecoder(fn: "GraphQLParser.time")
timestamp: last_updated @bsDecoder(fn: "GraphQLParser.timeMS")
}
},
|}
Expand Down
19 changes: 18 additions & 1 deletion scan/src/subscriptions/GraphQLParser.re
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,31 @@ let buffer = json =>
|> Js.String.substr(~from=2)
|> JsBuffer.fromHex;

let time = json => {
let timeS = json => {
json
|> Js.Json.decodeNumber
|> Belt.Option.getExn
|> int_of_float
|> MomentRe.momentWithUnix
|> MomentRe.Moment.defaultUtc;
};

let timeMS = json => {
json
|> Js.Json.decodeNumber
|> Belt.Option.getExn
|> MomentRe.momentWithTimestampMS
|> MomentRe.Moment.defaultUtc;
};

let optionBuffer = Belt_Option.map(_, buffer);

let optionTimeMS = Belt_Option.map(_, timeMS);

let optionTimeS = Belt_Option.map(_, timeS);

let optionTimeSExn = timeSOpt => timeSOpt |> Belt_Option.getExn |> timeS;

let bool = json => json |> Js.Json.decodeBoolean |> Belt.Option.getExn;

let hash = json =>
Expand Down
2 changes: 1 addition & 1 deletion scan/src/subscriptions/OracleScriptRevisionSub.re
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module RevisionsConfig = [%graphql
transaction @bsRecord {
txHash: tx_hash @bsDecoder(fn: "GraphQLParser.hash")
blockHeight: block_height @bsDecoder(fn: "ID.Block.fromJson")
timestamp @bsDecoder(fn: "GraphQLParser.time")
timestamp @bsDecoder(fn: "GraphQLParser.timeMS")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions scan/src/subscriptions/OracleScriptSub.re
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module MultiConfig = [%graphql
description
schema
sourceCodeURL: source_code_url
timestamp: last_updated @bsDecoder(fn: "GraphQLParser.time")
timestamp: last_updated @bsDecoder(fn: "GraphQLParser.timeMS")
related_data_sources @bsRecord {
dataSourceID: data_source_id @bsDecoder(fn: "ID.DataSource.fromJson")
}
Expand All @@ -64,7 +64,7 @@ module SingleConfig = [%graphql
description
schema
sourceCodeURL: source_code_url
timestamp: last_updated @bsDecoder(fn: "GraphQLParser.time")
timestamp: last_updated @bsDecoder(fn: "GraphQLParser.timeMS")
related_data_sources @bsRecord {
dataSourceID: data_source_id @bsDecoder(fn: "ID.DataSource.fromJson")
}
Expand Down
Loading

0 comments on commit 57218bf

Please sign in to comment.