Skip to content

Commit e9f2b6a

Browse files
committed
fix: Message serialization
1 parent 03b9416 commit e9f2b6a

File tree

14 files changed

+458
-492
lines changed

14 files changed

+458
-492
lines changed

package-lock.json

Lines changed: 351 additions & 337 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"license": "MIT",
1111
"dependencies": {
12-
"@iota/iota.js": "^1.9.0-stardust.4",
12+
"@iota/iota.js": "^1.9.0-stardust.5",
1313
"classnames": "^2.3.1",
1414
"humanize-duration": "^3.25.2",
1515
"moment": "^2.29.1",

src/app/components/tangle/Address.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { AddressProps } from "./AddressProps";
66
* Component which will display an address.
77
*/
88
class Address extends Component<AddressProps> {
9-
109
/**
1110
* Render the component.
1211
* @returns The node to render.

src/app/components/tangle/FeatureBlock.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { ISSUER_FEATURE_BLOCK_TYPE, METADATA_FEATURE_BLOCK_TYPE, SENDER_FEATURE_BLOCK_TYPE, serializeMessage, TAG_FEATURE_BLOCK_TYPE } from "@iota/iota.js";
2-
import { Converter } from "@iota/util.js";
1+
import { ISSUER_FEATURE_BLOCK_TYPE, METADATA_FEATURE_BLOCK_TYPE, SENDER_FEATURE_BLOCK_TYPE, TAG_FEATURE_BLOCK_TYPE } from "@iota/iota.js";
32
import React, { Component, ReactNode } from "react";
43
import { NameHelper } from "../../../utils/nameHelper";
54
import Address from "./Address";
@@ -9,21 +8,13 @@ import { FeatureBlockProps } from "./FeatureBlockProps";
98
* Component which will display an Feature Block.
109
*/
1110
class FeatureBlock extends Component<FeatureBlockProps> {
12-
/**
13-
* Create a new instance of Feature Block.
14-
* @param props The props.
15-
*/
16-
constructor(props: FeatureBlockProps) {
17-
super(props);
18-
}
19-
2011
/**
2112
* Render the component.
2213
* @returns The node to render.
2314
*/
2415
public render(): ReactNode {
2516
return (
26-
<div className="feature-block">
17+
<div className="feature-block padding-t-s">
2718
<h3>{NameHelper.getFeatureBlockTypeName(this.props.featureBlock.type)}</h3>
2819

2920
{this.props.featureBlock.type === SENDER_FEATURE_BLOCK_TYPE && (

src/app/components/tangle/Output.tsx

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ALIAS_OUTPUT_TYPE, FOUNDRY_OUTPUT_TYPE, NFT_OUTPUT_TYPE, TREASURY_OUTPUT_TYPE, UnitsHelper, IOutputResponse } from "@iota/iota.js";
1+
import { BASIC_OUTPUT_TYPE, ALIAS_OUTPUT_TYPE, FOUNDRY_OUTPUT_TYPE, NFT_OUTPUT_TYPE, TREASURY_OUTPUT_TYPE, UnitsHelper, IOutputResponse } from "@iota/iota.js";
22
import React, { Component, ReactNode } from "react";
33
import { Link } from "react-router-dom";
44
import { ClipboardHelper } from "../../../utils/clipboardHelper";
@@ -35,6 +35,7 @@ class Output extends Component<OutputProps, OutputState> {
3535
return (
3636
<div className="output">
3737
<h2>{NameHelper.getOutputTypeName(this.state.output.type)} {this.props.index}</h2>
38+
{/* Diplay metadata for Output Response */}
3839
{this.isOutputResponse(this.props.output) && (
3940
<React.Fragment>
4041
<div className="card--label">
@@ -202,57 +203,51 @@ class Output extends Component<OutputProps, OutputState> {
202203
</div>
203204
</React.Fragment>
204205
)}
205-
{(this.state.output.type === ALIAS_OUTPUT_TYPE ||
206-
this.state.output.type === NFT_OUTPUT_TYPE ||
207-
this.state.output.type === FOUNDRY_OUTPUT_TYPE) &&
208-
this.state.output.immutableBlocks && (
209-
<React.Fragment>
210-
<div className="card--label">
211-
Immutable Blocks:
212-
</div>
213-
<div className="card--value row">
214-
{this.state.output.immutableBlocks.map((immutableFeatureBlock, idx) => (
215-
<FeatureBlock
216-
key={idx}
217-
featureBlock={immutableFeatureBlock}
218-
/>
219-
))}
220-
</div>
221-
</React.Fragment>
222-
)}
223206

224-
{/* all output types except Treasury have commonn output conditions */}
207+
{/* all output types except Treasury have common output conditions */}
225208
{this.state.output.type !== TREASURY_OUTPUT_TYPE && (
226209
<React.Fragment>
227210
{this.state.output.unlockConditions.map((unlockCondition, idx) => (
228211
<UnlockCondition
229212
key={idx}
230213
unlockCondition={unlockCondition}
231214
/>
232-
))}
215+
))}
233216
{this.state.output.featureBlocks.map((featureBlock, idx) => (
234217
<FeatureBlock
235218
key={idx}
236219
featureBlock={featureBlock}
237220
/>
238-
))}
221+
))}
222+
{this.state.output.type !== BASIC_OUTPUT_TYPE && this.state.output.immutableFeatureBlocks && (
223+
<React.Fragment>
224+
{this.state.output.immutableFeatureBlocks.map((immutableFeatureBlock, idx) => (
225+
<FeatureBlock
226+
key={idx}
227+
featureBlock={immutableFeatureBlock}
228+
/>
229+
))}
230+
</React.Fragment>
231+
)}
239232
{this.state.output.nativeTokens.map((token, idx) => (
240233
<React.Fragment key={idx}>
241-
<h3>Native token</h3>
242-
<div className="card--label">
243-
Token id:
244-
</div>
245-
<div className="card--value row">
246-
{token.id}
247-
</div>
248-
<div className="card--label">
249-
Amount:
250-
</div>
251-
<div className="card--value row">
252-
{token.amount}
234+
<div className="native-token padding-t-s">
235+
<h3>Native token</h3>
236+
<div className="card--label">
237+
Token id:
238+
</div>
239+
<div className="card--value row">
240+
{token.id}
241+
</div>
242+
<div className="card--label">
243+
Amount:
244+
</div>
245+
<div className="card--value row">
246+
{token.amount}
247+
</div>
253248
</div>
254249
</React.Fragment>
255-
))}
250+
))}
256251
</React.Fragment>
257252
)}
258253

@@ -267,7 +262,7 @@ class Output extends Component<OutputProps, OutputState> {
267262
* @returns True of object is IOutputResponse.
268263
*/
269264
private isOutputResponse(object: unknown): object is IOutputResponse {
270-
return Object.prototype.hasOwnProperty.call(object, "messageId")
265+
return Object.prototype.hasOwnProperty.call(object, "messageId");
271266
}
272267
}
273268

src/app/components/tangle/ReceiptPayload.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { UnitsHelper } from "@iota/iota.js";
1+
import { ED25519_ADDRESS_TYPE, UnitsHelper } from "@iota/iota.js";
22
import React, { Component, ReactNode } from "react";
33
import { ServiceFactory } from "../../../factories/serviceFactory";
44
import { NodeConfigService } from "../../../services/nodeConfigService";
@@ -66,13 +66,14 @@ class ReceiptPayload extends Component<ReceiptPayloadProps, ReceiptPayloadState>
6666
{f.tailTransactionHash}
6767
</div>
6868
<div className="card--value card--value__mono">
69-
TODO:address
70-
{/* <Bech32Address
71-
activeLinks={true}
72-
addressDetails={
73-
Bech32AddressHelper.buildAddress(f.address.address, this._bech32Hrp)
74-
}
75-
/> */}
69+
{f.address.type === ED25519_ADDRESS_TYPE && (
70+
<Bech32Address
71+
activeLinks={true}
72+
addressDetails={
73+
Bech32AddressHelper.buildAddress(f.address.pubKeyHash, this._bech32Hrp)
74+
}
75+
/>
76+
)}
7677
</div>
7778
<div className="card--label">
7879
Deposit
@@ -87,9 +88,8 @@ class ReceiptPayload extends Component<ReceiptPayloadProps, ReceiptPayloadState>
8788
}
8889
)}
8990
>
90-
TODO:amount
91-
{/* {this.state.formatFull
92-
? `${f.deposit} i` : UnitsHelper.formatBest(f.deposit)} */}
91+
{this.state.formatFull
92+
? `${f.deposit} i` : UnitsHelper.formatBest(Number(f.deposit))}
9393
</button>
9494
</div>
9595
</div>
@@ -113,10 +113,9 @@ class ReceiptPayload extends Component<ReceiptPayloadProps, ReceiptPayloadState>
113113
}
114114
)}
115115
>
116-
TODO:amount
117-
{/* {this.state.formatFull
116+
{this.state.formatFull
118117
? `${this.props.payload.transaction.output.amount} i`
119-
: UnitsHelper.formatBest(this.props.payload.transaction.output.amount)} */}
118+
: UnitsHelper.formatBest(Number(this.props.payload.transaction.output.amount))}
120119
</button>
121120
</div>
122121
</div>

src/app/components/tangle/TransactionPayload.tsx

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable max-len */
2-
import { Ed25519Address, IReferenceUnlockBlock, ISignatureUnlockBlock, REFERENCE_UNLOCK_BLOCK_TYPE, SIGNATURE_UNLOCK_BLOCK_TYPE, UTXO_INPUT_TYPE, TREASURY_INPUT_TYPE } from "@iota/iota.js";
2+
import { Ed25519Address, IReferenceUnlockBlock, ISignatureUnlockBlock, UTXO_INPUT_TYPE, REFERENCE_UNLOCK_BLOCK_TYPE, SIGNATURE_UNLOCK_BLOCK_TYPE, ALIAS_UNLOCK_BLOCK_TYPE, NFT_UNLOCK_BLOCK_TYPE } from "@iota/iota.js";
33
import { Converter } from "@iota/util.js";
44
import React, { Component, ReactNode } from "react";
55
import { ServiceFactory } from "../../../factories/serviceFactory";
@@ -56,7 +56,6 @@ class TransactionPayload extends Component<TransactionPayloadProps, TransactionP
5656
}
5757

5858
this.state = {
59-
formatFull: false,
6059
unlockAddresses
6160
};
6261
}
@@ -99,17 +98,6 @@ class TransactionPayload extends Component<TransactionPayloadProps, TransactionP
9998
</div>
10099
</React.Fragment>
101100
)}
102-
{input.type === TREASURY_INPUT_TYPE && (
103-
<React.Fragment>
104-
<div className="card--label">
105-
Treasury Input
106-
</div>
107-
<div className="card--value card--value__mono">
108-
{input}
109-
</div>
110-
111-
</React.Fragment>
112-
)}
113101
</div>
114102
))}
115103
</div>
@@ -162,6 +150,26 @@ class TransactionPayload extends Component<TransactionPayloadProps, TransactionP
162150
</div>
163151
</React.Fragment>
164152
)}
153+
{unlockBlock.type === ALIAS_UNLOCK_BLOCK_TYPE && (
154+
<React.Fragment>
155+
<div className="card--label">
156+
Reference
157+
</div>
158+
<div className="card--value">
159+
{unlockBlock.reference}
160+
</div>
161+
</React.Fragment>
162+
)}
163+
{unlockBlock.type === NFT_UNLOCK_BLOCK_TYPE && (
164+
<React.Fragment>
165+
<div className="card--label">
166+
Reference
167+
</div>
168+
<div className="card--value">
169+
{unlockBlock.reference}
170+
</div>
171+
</React.Fragment>
172+
)}
165173
</div>
166174
))}
167175
</div>

src/app/components/tangle/TransactionPayloadState.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { IBech32AddressDetails } from "../../../models/IBech32AddressDetails";
22

33
export interface TransactionPayloadState {
4-
/**
5-
* Format the curreny in full.
6-
*/
7-
formatFull?: boolean;
84

95
/**
106
* The unlock addresses for the transactions.

src/app/components/tangle/UnlockCondition.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ import { UnlockConditionProps } from "./UnlockConditionProps";
88
* Component which will display an unlock condition.
99
*/
1010
class UnlockCondition extends Component<UnlockConditionProps> {
11-
1211
/**
1312
* Render the component.
1413
* @returns The node to render.
1514
*/
1615
public render(): ReactNode {
1716
return (
18-
<div className="unlock-condition">
17+
<div className="unlock-condition padding-t-s">
1918
<h3>{NameHelper.getUnlockConditionTypeName(this.props.unlockCondition.type)}</h3>
2019

2120
{this.props.unlockCondition.type === ADDRESS_UNLOCK_CONDITION_TYPE && (
@@ -65,9 +64,6 @@ class UnlockCondition extends Component<UnlockConditionProps> {
6564
)}
6665
{this.props.unlockCondition.type === EXPIRATION_UNLOCK_CONDITION_TYPE && (
6766
<React.Fragment>
68-
<div className="card--label">
69-
Return address:
70-
</div>
7167
<Address
7268
address={this.props.unlockCondition.returnAddress}
7369
/>

src/app/routes/Search.tsx

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -133,29 +133,22 @@ class Search extends AsyncComponent<RouteComponentProps<SearchRouteProps>, Searc
133133
} else {
134134
let objType;
135135
let objParam = query;
136-
console.log("Search response:");
137-
console.log(response);
136+
138137
if (response.message) {
139138
objType = "message";
140-
console.log("objType message");
141-
// console.log(JSON.stringify(response))
142139
// Recalculate the message id from the content, in case
143140
// the lookup was a response to a transaction id lookup
144-
// const writeStream = new WriteStream();
145-
// try {
146-
// serializeMessage(writeStream, response.message);
147-
// } catch (error) {
148-
// console.log("serializeMessage error");
149-
// console.log(error);
141+
const writeStream = new WriteStream();
150142

151-
// if (error instanceof Error) {console.log(error.message)};
152-
// }
153-
// serializeMessage(writeStream, response.message);
154-
// objParam = Converter.bytesToHex(Blake2b.sum256(writeStream.finalBytes()));
155-
objParam = query;
156-
}
157-
// TODO:address
158-
else if (response?.address) {
143+
try {
144+
serializeMessage(writeStream, response.message);
145+
} catch (error) {
146+
if (error instanceof Error) {
147+
console.log(error.message);
148+
}
149+
}
150+
objParam = Converter.bytesToHex(Blake2b.sum256(writeStream.finalBytes()), true);
151+
} else if (response?.address) {
159152
objType = "address";
160153
} else if (response.indexMessageIds) {
161154
objType = "indexed";

0 commit comments

Comments
 (0)