Skip to content
Permalink
Browse files

Improvements to examples

- Show block num in search-lastest-transactions.ts
- Made the `reference/search-transactions.ts` a real reference example
  • Loading branch information...
maoueh committed May 31, 2019
1 parent 2efa035 commit 28aa2a062dc16afaea09468e0570bc4a7e1a6c3f
Showing with 10 additions and 23 deletions.
  1. +8 −3 examples/basic/search-your-latest-transactions.ts
  2. +2 −20 examples/reference/search-transactions.ts
@@ -7,7 +7,7 @@ async function main() {
const client = createDfuseClient({ apiKey: DFUSE_API_KEY, network: DFUSE_API_NETWORK })

try {
const response = await client.searchTransactions(`auth:${account}`, {
const response = await client.searchTransactions(`auth:${account} status:executed`, {
limit: 10,
sort: "desc"
})
@@ -20,8 +20,13 @@ async function main() {
return
}

response.transactions.forEach((result: SearchTransactionRow) => {
console.log("- " + buildEosqLink(result.lifecycle.id))
const transactions = response.transactions || []
transactions.forEach((result: SearchTransactionRow) => {
console.log(
`- ${buildEosqLink(result.lifecycle.id)} (Block #${
result.lifecycle.execution_trace!.block_num
})`
)
})
console.log()
} catch (error) {
@@ -1,5 +1,5 @@
import { DFUSE_API_KEY, runMain, prettifyJson, DFUSE_API_NETWORK } from "../config"
import { createDfuseClient, SearchTransactionRow } from "@dfuse/client"
import { createDfuseClient } from "@dfuse/client"

async function main() {
const client = createDfuseClient({ apiKey: DFUSE_API_KEY, network: DFUSE_API_NETWORK })
@@ -9,25 +9,7 @@ async function main() {
limit: 10
})

console.log(`Search transactions response`, prettifyJson(response))

console.log()
console.log(`Search transactions results (${response.transactions.length})`)
response.transactions.forEach((result: SearchTransactionRow) => {
const blockHeader = result.lifecycle.execution_block_header
const blockNum = parseInt(blockHeader.previous.substring(0, 8), 16) + 1

console.log(
` - ${result.lifecycle.id} [Actions ${result.action_idx.join(", ")}] (${blockNum} @ ${
blockHeader.timestamp
})`
)
}, response.transactions)

if (response.cursor) {
console.log("")
console.log("Cursor: " + response.cursor)
}
console.log(prettifyJson(response))
} catch (error) {
console.log("An error occurred", error)
}

0 comments on commit 28aa2a0

Please sign in to comment.
You can’t perform that action at this time.