Skip to content

Commit b35d088

Browse files
committed
fix: Remove search by index
1 parent b611d95 commit b35d088

File tree

3 files changed

+65
-86
lines changed

3 files changed

+65
-86
lines changed

src/app/components/tangle/TransactionPayload.tsx

Lines changed: 48 additions & 32 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, BASIC_OUTPUT_TYPE, ADDRESS_UNLOCK_CONDITION_TYPE, UnitsHelper, UTXO_INPUT_TYPE } from "@iota/iota.js";
2+
import { Ed25519Address, IReferenceUnlockBlock, ISignatureUnlockBlock, REFERENCE_UNLOCK_BLOCK_TYPE, SIGNATURE_UNLOCK_BLOCK_TYPE, BASIC_OUTPUT_TYPE, ADDRESS_UNLOCK_CONDITION_TYPE, UnitsHelper, UTXO_INPUT_TYPE, TREASURY_INPUT_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";
@@ -98,6 +98,17 @@ class TransactionPayload extends Component<TransactionPayloadProps, TransactionP
9898
</div>
9999
</React.Fragment>
100100
)}
101+
{input.type === TREASURY_INPUT_TYPE && (
102+
<React.Fragment>
103+
<div className="card--label">
104+
Treasury Input
105+
</div>
106+
<div className="card--value card--value__mono">
107+
{input}
108+
</div>
109+
110+
</React.Fragment>
111+
)}
101112
</div>
102113
))}
103114
</div>
@@ -114,41 +125,46 @@ class TransactionPayload extends Component<TransactionPayloadProps, TransactionP
114125
>
115126
<h3 className="margin-b-t">{NameHelper.getOutputTypeName(output.type)} {idx}</h3>
116127
{(() => {
128+
117129
if(output.type === BASIC_OUTPUT_TYPE ) {
118130
const addressUnlockCondition = output.unlockConditions
119-
.find(u => u.type === ADDRESS_UNLOCK_CONDITION_TYPE);
120-
if (addressUnlockCondition &&
121-
addressUnlockCondition.type === ADDRESS_UNLOCK_CONDITION_TYPE) {
131+
.find(u => u.type === ADDRESS_UNLOCK_CONDITION_TYPE);
122132

123-
return ( <React.Fragment>
124-
{/* <Bech32Address
125-
activeLinks={true}
126-
addressDetails={Bech32AddressHelper.buildAddress(addressUnlockCondition.address, this._bech32Hrp)}
127-
/> */}
128-
129-
<div className="card--label">
130-
Amount
131-
</div>
132-
<div className="card--value card--value__mono">
133-
<button
134-
className="card--value--button"
135-
type="button"
136-
onClick={() => this.setState(
137-
{
138-
formatFull: !this.state.formatFull
139-
}
140-
)}
141-
>
142-
{`${output.amount} i`}
143-
TODO:amount
144-
{/* {this.state.formatFull
145-
? `${output.amount} i`
146-
: UnitsHelper.formatBest(output.amount)} */}
147-
</button>
133+
return ( <React.Fragment>
134+
<div className="card--label">
135+
Amount
136+
</div>
137+
<div className="card--value card--value__mono">
138+
<button
139+
className="card--value--button"
140+
type="button"
141+
onClick={() => this.setState(
142+
{
143+
formatFull: !this.state.formatFull
144+
}
145+
)}
146+
>
147+
{`${output.amount} i`}
148+
{this.state.formatFull
149+
? `${output.amount} i`
150+
: UnitsHelper.formatBest(Number(output.amount))}
151+
</button>
152+
</div>
153+
{ addressUnlockCondition &&
154+
addressUnlockCondition.type === ADDRESS_UNLOCK_CONDITION_TYPE && (
155+
<div>
156+
<div className="card--label">
157+
Address unlock condition:
158+
</div>
159+
<div>
160+
{addressUnlockCondition}
161+
</div>
148162
</div>
149-
</React.Fragment>)
150-
}
151-
}
163+
)
164+
}
165+
166+
</React.Fragment>)
167+
}
152168
})()}
153169
</div>
154170
)}

src/app/routes/explorer/Message.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ class Message extends AsyncComponent<RouteComponentProps<MessageRouteProps>, Mes
6262
const result = await this._tangleService.search(this.props.match.params.messageId);
6363

6464
if (result?.message) {
65-
//TODO: uncomment once hornet and iota.rs get updated to new version with correct payload types.
66-
// iota.js currently ahead of hornet and opta.rs ex. TRANSACTION_PAYLOAD_TYPE = 6 while in hornet and iota.rs TRANSACTION_PAYLOAD_TYPE = 0
67-
const writeStream = new WriteStream();
68-
serializeMessage(writeStream, result.message);
69-
const finalBytes = writeStream.finalBytes();
65+
// TODO: uncomment once HORNET gets updated to new version with correct payload types.
66+
// iota.js currently ahead of hornet ex. TRANSACTION_PAYLOAD_TYPE = 6 while in hornet and iota.rs TRANSACTION_PAYLOAD_TYPE = 0
67+
// const writeStream = new WriteStream();
68+
// serializeMessage(writeStream, result.message);
69+
// const finalBytes = writeStream.finalBytes();
7070

7171
const dataUrls = {
7272
json: DownloadHelper.createJsonDataUrl(result.message),
@@ -322,6 +322,9 @@ class Message extends AsyncComponent<RouteComponentProps<MessageRouteProps>, Mes
322322
* Update the message details.
323323
*/
324324
private async updateMessageDetails(): Promise<void> {
325+
// TODO: remove comments once HORNET gets updated
326+
// Getting message details dosent work for message that was retrieverd by searching for transaction id, also known as the Transaction Included Message look up.
327+
// Will work once HORNET gets updated to new version with correct payload types.
325328
const details = await this._tangleService.messageDetails(this.props.match.params.messageId);
326329

327330
this.setState({

src/services/tangleService.ts

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class TangleService {
5050
try {
5151
// If the query is an integer then lookup a milestone
5252
if (/^\d+$/.test(query)) {
53-
console.log("tangelSearch milestone")
53+
console.log("tangelSearch: milestone")
5454
const milestone = await client.milestone(Number.parseInt(query, 10));
5555

5656
return {
@@ -70,6 +70,7 @@ export class TangleService {
7070
await this.info();
7171
}
7272
if (this._nodeInfo && Bech32Helper.matches(queryLower, this._nodeInfo.protocol.bech32HRP)) {
73+
console.log("tangelSearch: address bech32")
7374
const address = await this.addressBalance(queryLower);
7475

7576
if (address) {
@@ -92,8 +93,9 @@ export class TangleService {
9293

9394
// If the query is 64 bytes hex, try and look for a message
9495
if (Converter.isHex(queryLower) && queryLower.length === 64) {
95-
console.log("tangelSearch message")
96+
9697
try {
98+
console.log("tangelSearch: message")
9799
const message = await client.message(queryLower);
98100

99101
return {
@@ -109,8 +111,7 @@ export class TangleService {
109111

110112
// If the query is 64 bytes hex, try and look for a transaction included message
111113
try {
112-
console.log("tangelSearch transaction-included-message")
113-
114+
console.log("tangelSearch: transaction-included-message")
114115
const message = await client.transactionIncludedMessage(queryLower);
115116
return {
116117
message
@@ -127,7 +128,7 @@ export class TangleService {
127128
try {
128129
// If the query is 68 bytes hex, try and look for an output
129130
if (Converter.isHex(queryLower) && queryLower.length === 68) {
130-
console.log("tangelSearch output")
131+
console.log("tangelSearch: output")
131132
const output = await client.output(queryLower);
132133

133134
return {
@@ -147,7 +148,7 @@ export class TangleService {
147148
await this.info();
148149
}
149150
if (this._nodeInfo && Converter.isHex(queryLower) && queryLower.length === 64) {
150-
console.log("tangelSearch address ed25519")
151+
console.log("tangelSearch: address ed25519")
151152
// We have 64 characters hex so could possible be a raw ed25519 address
152153
// const address = await client.addressEd25519(queryLower);
153154
// const addressOutputs = await client.addressEd25519Outputs(queryLower);
@@ -156,7 +157,8 @@ export class TangleService {
156157
const bech32 = Bech32Helper.toBech32(ED25519_ADDRESS_TYPE, Converter.hexToBytes(queryLower), this._nodeInfo.protocol.bech32HRP)
157158
const address = await this.addressBalance(bech32);
158159

159-
if (address) {
160+
// TODO: confirm address.ledgerIndex > 0 condition is valid way to decide if address exists? Address object will always be retrieved even for bech32 addresses that dont exist.
161+
if (address && address.ledgerIndex > 0) {
160162
const indexerPlugin = new IndexerPluginClient(client);
161163
const addressOutputs = await indexerPlugin.outputs({addressBech32: bech32});
162164
return {
@@ -173,48 +175,6 @@ export class TangleService {
173175
}
174176
}
175177

176-
try {
177-
if (query.length > 0) {
178-
let messages;
179-
let indexMessageType: "utf8" | "hex" | undefined;
180-
console.log("tangelSearch final message search")
181-
// If the query is between 2 and 128 hex chars assume hex encoded bytes
182-
if (query.length >= 2 && query.length <= 128 && Converter.isHex(queryLower)) {
183-
console.log("1. try")
184-
console.log(queryLower)
185-
messages = await client.message(queryLower);
186-
console.log(messages)
187-
// if (messages.count > 0) {
188-
indexMessageType = "hex";
189-
// }
190-
}
191-
192-
// If not already found and query less than 64 bytes assume its UTF8
193-
if (!indexMessageType && query.length <= 64) {
194-
console.log("2. try")
195-
messages = await client.message(query);
196-
console.log(messages)
197-
// if (messages.count > 0) {
198-
indexMessageType = "utf8";
199-
// }
200-
}
201-
202-
// if (messages && messages.count > 0) {
203-
if (messages) {
204-
return {
205-
indexMessageIds: messages.parentMessageIds,
206-
indexMessageType
207-
};
208-
}
209-
}
210-
} catch (err) {
211-
if (err instanceof ClientError && this.checkForUnavailable(err)) {
212-
return {
213-
unavailable: true
214-
};
215-
}
216-
}
217-
218178
return {};
219179
}
220180

0 commit comments

Comments
 (0)