Skip to content

Commit

Permalink
Use DocType instead of Block, Parcel, Transaction in sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilyoung Kim committed Jul 18, 2018
1 parent 37958dc commit 499b277
Show file tree
Hide file tree
Showing 42 changed files with 1,610 additions and 341 deletions.
4 changes: 2 additions & 2 deletions client/components/asset/AssetDetails/AssetDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as React from "react";
import { AssetScheme } from "codechain-sdk/lib/core/classes";

import "./AssetDetails.scss"
import AssetHeaderTable from "../AssetHeaderTable/AssetHeaderTable";
import { AssetSchemeDoc } from "../../../db/DocType";

interface OwnProps {
assetScheme: AssetScheme;
assetScheme: AssetSchemeDoc;
}

const AssetDetails = (prop: OwnProps) => {
Expand Down
6 changes: 3 additions & 3 deletions client/components/asset/AssetHeaderTable/AssetHeaderTable.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as React from "react";

import "./AssetHeaderTable.scss"
import { AssetScheme } from "codechain-sdk/lib/core/classes";
import HexString from "../../util/HexString/HexString";
import { AssetSchemeDoc } from "../../../db/DocType";

interface OwnProps {
assetScheme: AssetScheme;
assetScheme: AssetSchemeDoc;
}

interface MetadataFormat {
Expand Down Expand Up @@ -41,7 +41,7 @@ const AssetHeaderTable = (prop: OwnProps) => {
</tr>
<tr>
<td>Registrar</td>
<td>{prop.assetScheme.registrar ? (prop.assetScheme.registrar.value ? <HexString link={`/addr-platform/0x${prop.assetScheme.registrar.value}`} text={(prop.assetScheme.registrar.value as string)} /> : "Not existed") : "Not existed"}</td>
<td>{prop.assetScheme.registrar ? <HexString link={`/addr-platform/0x${prop.assetScheme.registrar}`} text={prop.assetScheme.registrar} /> : "Not existed"}</td>
</tr>
<tr>
<td>Description</td>
Expand Down
11 changes: 3 additions & 8 deletions client/components/asset/AssetList/AssetList.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import * as React from "react";
import * as _ from "lodash";
import { Asset, AssetScheme } from "codechain-sdk/lib/core/classes";

import "./AssetList.scss";
import HexString from "../../util/HexString/HexString";

interface AssetBundle {
asset: Asset,
assetScheme: AssetScheme
}
import { AssetBundleDoc } from "../../../db/DocType";

interface OwnProps {
assetBundles: AssetBundle[]
assetBundles: AssetBundleDoc[]
}

interface MetadataFormat {
Expand Down Expand Up @@ -41,7 +36,7 @@ const AssetList = (prop: OwnProps) => {
Asset
</td>
<td>
<HexString text={assetBundle.asset.assetType.value} />
<HexString text={assetBundle.asset.assetType} />
</td>
</tr>
<tr>
Expand Down
9 changes: 3 additions & 6 deletions client/components/assetTransferAddress/UTXOList/UTXOList.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import * as React from "react";
import * as _ from "lodash";
import { Asset, AssetScheme } from "codechain-sdk/lib/core/classes";

import "./UTXOList.scss";
import HexString from "../../util/HexString/HexString";
import { AssetBundleDoc } from "../../../db/DocType";

interface OwnProps {
utxo: Array<{
asset: Asset,
assetScheme: AssetScheme
}>;
utxo: AssetBundleDoc[];
}

interface MetadataFormat {
Expand Down Expand Up @@ -43,7 +40,7 @@ const UTXOList = (prop: OwnProps) => {
<tbody>
<tr>
<td>AssetType</td>
<td><HexString link={`/asset/0x${utxo.asset.assetType.value}`} text={utxo.asset.assetType.value} /></td>
<td><HexString link={`/asset/0x${utxo.asset.assetType}`} text={utxo.asset.assetType} /></td>
</tr>
<tr>
<td>Amount</td>
Expand Down
18 changes: 9 additions & 9 deletions client/components/block/BlockDetails/BlockDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as React from "react";

import { Block } from "codechain-sdk/lib/core/classes";
import { Col, Row } from 'reactstrap';

import "./BlockDetails.scss"
import HexString from "../../util/HexString/HexString";
import { BlockDoc } from "../../../db/DocType";

interface OwnProps {
block: Block;
block: BlockDoc;
}

class BlockDetails extends React.Component<OwnProps> {
Expand All @@ -20,39 +20,39 @@ class BlockDetails extends React.Component<OwnProps> {
Hash
</Col>
<Col md="10">
<HexString text={block.hash.value} />
<HexString text={block.hash} />
</Col>
</Row>
<Row>
<Col md="2">
Parent Block Hash
</Col>
<Col md="10">
<HexString link={`/block/0x${block.parentHash.value}`} text={block.parentHash.value} />
<HexString link={`/block/0x${block.parentHash}`} text={block.parentHash} />
</Col>
</Row>
<Row>
<Col md="2">
Parcels Root
</Col>
<Col md="10">
<HexString text={block.parcelsRoot.value} />
<HexString text={block.parcelsRoot} />
</Col>
</Row>
<Row>
<Col md="2">
Invoices Root
</Col>
<Col md="10">
<HexString text={block.invoicesRoot.value} />
<HexString text={block.invoicesRoot} />
</Col>
</Row>
<Row>
<Col md="2">
State Root
</Col>
<Col md="10">
<HexString text={block.stateRoot.value} />
<HexString text={block.stateRoot} />
</Col>
</Row>
<Row>
Expand All @@ -68,7 +68,7 @@ class BlockDetails extends React.Component<OwnProps> {
Author
</Col>
<Col md="10">
<HexString link={`/addr-platform/0x${block.author.value}`} text={block.author.value} />
<HexString link={`/addr-platform/0x${block.author}`} text={block.author} />
</Col>
</Row>
<Row>
Expand All @@ -84,7 +84,7 @@ class BlockDetails extends React.Component<OwnProps> {
Score
</Col>
<Col md="10">
{block.score.value.toString()}
{block.score}
</Col>
</Row>
<Row>
Expand Down
8 changes: 4 additions & 4 deletions client/components/block/BlockList/BlockList.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as React from "react";
import * as _ from "lodash";
import { Block, ChangeShardState } from "codechain-sdk/lib/core/classes";

import "./BlockList.scss";
import HexString from "../../util/HexString/HexString";
import { BlockDoc, Type, ChangeShardStateDoc } from "../../../db/DocType";

interface OwnProps {
blocks: Block[]
blocks: BlockDoc[]
}

const BlockList = (prop: OwnProps) => {
Expand All @@ -20,7 +20,7 @@ const BlockList = (prop: OwnProps) => {
Block #{block.number}
</td>
<td>
<HexString text={block.hash.value} />
<HexString text={block.hash} />
</td>
</tr>
<tr>
Expand All @@ -33,7 +33,7 @@ const BlockList = (prop: OwnProps) => {
</tr>
<tr>
<td>Count of transactions</td>
<td>{_.sumBy(block.parcels, (parcel) => (parcel.unsigned.action instanceof ChangeShardState ? parcel.unsigned.action.transactions.length : 0))}</td>
<td>{_.sumBy(block.parcels, (parcel) => (Type.isChangeShardStateDoc(parcel.action) ? (parcel.action as ChangeShardStateDoc).transactions.length : 0))}</td>
</tr>
<tr>
<td>Timestamp</td>
Expand Down
33 changes: 16 additions & 17 deletions client/components/block/BlockParcelList/BlockParcelList.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import * as React from "react";

import { SignedParcel, ChangeShardState, Payment, SetRegularKey } from "codechain-sdk/lib/core/classes";

import "./BlockParcelList.scss"
import HexString from "../../util/HexString/HexString";
import { Row, Col } from "reactstrap";
import * as arrow from "./img/arrow.png";
import { ParcelDoc, Type, PaymentDoc, ChangeShardStateDoc, SetRegularKeyDoc } from "../../../db/DocType";

interface Props {
parcels: SignedParcel[];
parcels: ParcelDoc[];
}

const ParcelObjectByType = (parcel: SignedParcel) => {
if (parcel.unsigned.action instanceof Payment) {
const ParcelObjectByType = (parcel: ParcelDoc) => {
if (Type.isPaymentDoc(parcel.action)) {
return ([
<Row key="payment-amount">
<Col md="2">
Amount
</Col>
<Col md="10">
{parcel.unsigned.action.amount.value.toString()}
{(parcel.action as PaymentDoc).amount}
</Col>
</Row>,
<Row key="payment-sender-receiver">
Expand All @@ -32,7 +31,7 @@ const ParcelObjectByType = (parcel: SignedParcel) => {
Sender
</Col>
<Col md="7">
<HexString link={`/addr-platform/0x${parcel.getSender().value}`} text={parcel.getSender().value} length={15} />
<HexString link={`/addr-platform/0x${parcel.sender}`} text={parcel.sender} length={15} />
</Col>
</Row>
</Col>
Expand All @@ -45,15 +44,15 @@ const ParcelObjectByType = (parcel: SignedParcel) => {
Receiver
</Col>
<Col md="7">
<HexString link={`/addr-platform/0x${parcel.unsigned.action.receiver.value}`} text={parcel.unsigned.action.receiver.value} length={15} />
<HexString link={`/addr-platform/0x${(parcel.action as PaymentDoc).receiver}`} text={(parcel.action as PaymentDoc).receiver} length={15} />
</Col>
</Row>
</Col>
</Row>
</div>
</Col>
</Row>])
} else if (parcel.unsigned.action instanceof ChangeShardState) {
} else if (Type.isChangeShardStateDoc(parcel.action)) {
return <Row>
<Col>
<div className="background-highlight">
Expand All @@ -62,19 +61,19 @@ const ParcelObjectByType = (parcel: SignedParcel) => {
Count of Txs
</Col>
<Col md="10">
{parcel.unsigned.action.transactions.length}
{(parcel.action as ChangeShardStateDoc).transactions.length}
</Col>
</Row>
</div>
</Col>
</Row>
} else if (parcel.unsigned.action instanceof SetRegularKey) {
} else if (Type.isSetRegularKeyDoc(parcel.action)) {
return <Row>
<Col md="2">
Key
</Col>
<Col md="10">
<HexString text={parcel.unsigned.action.key.value} />
<HexString text={(parcel.action as SetRegularKeyDoc).key} />
</Col>
</Row>
}
Expand All @@ -95,10 +94,10 @@ const getClassNameByType = (type: string) => {
const BlockParcelList = (props: Props) => {
const { parcels } = props;
return <div className="block-parcel-list">{parcels.map((parcel, i: number) => {
const hash = parcel.hash().value;
const hash = parcel.hash;
return <div key={`block-parcel-${hash}`} className="parcel-item">
<div className={`type ${getClassNameByType(parcel.unsigned.action.toJSON().action)}`}>
{parcel.unsigned.action.toJSON().action}
<div className={`type ${getClassNameByType(parcel.action.action)}`}>
{parcel.action.action}
</div>
<Row>
<Col md="2">
Expand All @@ -113,15 +112,15 @@ const BlockParcelList = (props: Props) => {
Signer
</Col>
<Col md="10">
<HexString link={`/address/0x${parcel.getSender().value}`} text={parcel.getSender().value} />
<HexString link={`/address/0x${parcel.sender}`} text={parcel.sender} />
</Col>
</Row>
<Row>
<Col md="2">
Fee
</Col>
<Col md="10">
{parcel.unsigned.fee.value.toString()}
{parcel.fee}
</Col>
</Row>
{ParcelObjectByType(parcel)}
Expand Down
9 changes: 4 additions & 5 deletions client/components/home/LatestBlocks/LatestBlocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import * as moment from "moment";
import { Table } from 'reactstrap';
import { Link } from "react-router-dom";

import { Block } from "codechain-sdk/lib/core/classes";

import './LatestBlocks.scss';
import HexString from "../../util/HexString/HexString";
import { BlockDoc } from "../../../db/DocType";

interface Props {
blocksByNumber: {
[n: number]: Block;
[n: number]: BlockDoc;
}
}

Expand All @@ -34,11 +33,11 @@ const LatestBlocks = (props: Props) => {
{
_.map(_.reverse(_.values(blocksByNumber)), block => {
return (
<tr key={`home-block-num-${block.hash.value}`}>
<tr key={`home-block-num-${block.hash}`}>
<td scope="row"><Link to={`/block/${block.number}`}>{block.number}</Link></td>
<td>{block.parcels.length}</td>
<td>Block Reward</td>
<td><HexString link={`/addr-platform/0x${block.author.value}`} text={block.author.value} length={10} /></td>
<td><HexString link={`/addr-platform/0x${block.author}`} text={block.author} length={10} /></td>
<td>{moment.unix(block.timestamp).fromNow()}</td>
</tr>
);
Expand Down
15 changes: 7 additions & 8 deletions client/components/home/LatestParcels/LatestParcels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import * as _ from "lodash";
import * as moment from "moment";
import { Table } from 'reactstrap';

import { Block } from "codechain-sdk/lib/core/classes";

import './LatestParcels.scss';
import HexString from "../../util/HexString/HexString";
import { BlockDoc } from "../../../db/DocType";

interface Props {
blocksByNumber: {
[n: number]: Block;
[n: number]: BlockDoc;
}
}

Expand All @@ -33,13 +32,13 @@ const LatestParcels = (props: Props) => {
{
_.map(_.reverse(_.values(blocksByNumber)), block => {
return _.map(block.parcels, (parcel) => {
const actionString = parcel.unsigned.action.toJSON().action;
const actionString = parcel.action.action;
return (
<tr key={`home-parcel-${parcel.hash().value}`}>
<tr key={`home-parcel-${parcel.hash}`}>
<td><div className={`parcel-type text-center ${actionString === "changeShardState" ? "change-shard-state-type" : (actionString === "payment" ? "payment-type" : "set-regular-key-type")}`}>{actionString}</div></td>
<td scope="row"><HexString link={`/parcel/0x${parcel.hash().value}`} text={parcel.hash().value} length={10} /></td>
<td><HexString link={`/addr-platform/0x${parcel.getSender().value}`} text={parcel.getSender().value} length={10} /></td>
<td>{parcel.unsigned.fee.value.toString(10)}</td>
<td scope="row"><HexString link={`/parcel/0x${parcel.hash}`} text={parcel.hash} length={10} /></td>
<td><HexString link={`/addr-platform/0x${parcel.sender}`} text={parcel.sender} length={10} /></td>
<td>{parcel.fee}</td>
<td>{moment.unix(block.timestamp).fromNow()}</td>
</tr>
);
Expand Down
Loading

0 comments on commit 499b277

Please sign in to comment.