Skip to content
Permalink
Browse files

Fixed typings problems around *Op fields

Started some deprecation renames (`DBOp` -> `DbOp` and `RAMOp` -> `RamOp`).
Moved some common typings into a `common.ts` file directly.

Fixed `ActionTraceData` `dbops` not using the right `DbOp` type as well
as fixing the collision between redefinition of `DbOp` type.
  • Loading branch information...
maoueh committed Apr 30, 2019
1 parent 6d2e73e commit 5002779839ae81fa2e7e548422a4fb7726bf8243
@@ -2,6 +2,27 @@

## In progress

- Renamed `ActionTraceData` `DbOp` to `ActionTraceDbOp`. This fixes
a problem where `DbOp` type from library was always the `TableDeltaData`
one since they were conflicting having the same name. This rename is **not**
a breaking change since it was impossible to import the type.

- Fix `ActionTraceData` `dbops` field definition which was incorrectly
using `TableDeltaData` `DbOp` definition while not being the same at all.

**Warning** Requires some modification steps (resolving new compilation
errors for some usage of the library's types). See
[From '@dfuse/client@0.2.3' to '@dfuse/client@0.2.4'](./MIGRATION.md#from-dfuseclient023-to-dfuseclient024)
section in migration guide.

- Removed duplicated `DbOp` definition which was wrong anyway.

- Deprecated `RAMOP` (renamed to `RamOp`).

- Deprecated `DBOp` (renamed to `DbOp`).

## 0.2.3 (April 30, 2019)

- Fixed typing mismatch between dfuse WebSocket API JSON output
and our own type definitions.

@@ -6,6 +6,12 @@ Table of contents:
- [From `@dfuse/client@0.2.0` to `@dfuse/client@0.2.1`](#from-dfuseclient020-to-dfuseclient021)
- [From `@dfuse/client@0.2.2` to `@dfuse/client@0.2.3`](#from-dfuseclient022-to-dfuseclient023)

The on-going list of breaking changes from current major to next one
can be consulted at the end of the document. You are encourage to fix
deprecation notices right now (when available).

- [From `@dfuse/client@0.2.x` to `@dfuse/client@next`](#from-dfuseclient022-to-dfuseclientnext)

### From `@dfuse/eosws-js` to `@dfuse/client`

The first step is to remove the old library from your package and
@@ -184,4 +190,28 @@ Renames:
- `dtrxOps => dtrxops`
- `tableOps => tableops`

There is a also a some string fields, all `op` fields that are now
restricted to only their valid set of strings.

Simply update by fixing the compilations errors, which is a plain rename.

### From `@dfuse/client@0.2.3` to `@dfuse/client@0.2.4`

Might break compilations on some projects but occurs in bug fix version
bump considered bug against dfuse API real typings.

You will now get compilations errors around some models, mainly around
action trace fields. Also, the `ActionTraceData` now takes only one
generic parameter versus 2 before, the second one can be removed, was
used to type `ActionTraceDbOp` row's data but it's always an hexadecimal
encoded string.

Simply update by fixing the compilations errors, re-working your logic
to handle those corner cases that were ignored before.

### From `@dfuse/client@0.2.x` to `@dfuse/client@next`

Some types were rename, here the massive rename that can be done:

- Rename any occurrences of `RAMPOp` type to `RamOp`.
- Rename any occurrences of `DBOp` type to `DbOp`.
@@ -2,7 +2,7 @@ import { DFUSE_API_KEY, runMain, DFUSE_API_NETWORK } from "../config"
import {
createDfuseClient,
SearchTransactionRow,
RAMOp,
RamOp,
DfuseClient,
flattenActionTraces,
waitFor
@@ -76,7 +76,7 @@ async function main() {
// */
// const actionTraces = matchingActionTraces(result)

result.lifecycle.ramops!.forEach((ramOp: RAMOp) => {
result.lifecycle.ramops!.forEach((ramOp: RamOp) => {
// FIXME: Right logic for RAM op!

runningTotal += ramOp.delta
@@ -20,6 +20,46 @@ async function main() {
return
}

/**
* JSON examples of various fields possibilities (since they might
* not always appear in the streaming time frame):
*
* ```
* {
* dbops: [
* // An `ActionTraceDbOp` row update operation
* {
* "op": "UPD",
* "action_idx": 8,
* "opayer": "eosbetbank11",
* "npayer": "eosbetbank11",
* "path": "eosio.token/eosbetbank11/accounts/........ehbo5",
* "old": "d11a231c0000000004454f5300000000",
* "new": "cd1a231c0000000004454f5300000000"
* },
*
* // An `ActionTraceDbOp` row insertion operation
* {
* "op": "INS",
* "action_idx": 0,
* "npayer": "hj1111111534",
* "path": "eosio.token/hj1111111125/accounts/........ehbo5",
* "new": "c02709000000000004454f5300000000"
* }
*
* // An `ActionTraceDbOp` row removal operation
* {
* "op": "REM",
* "action_idx": 2,
* "opayer": "trustdicewin",
* "path": "trustdicewin/trustdicewin/hash/......1iwm13h",
* "old": "90bd994111e45fc947f7f7d4823081cdf13d05c12f31bf2049aec55e170aa0bcbf66c85c00000000"
* },
* ]
* }
* ```
*/

console.log(prettifyJson(message.data))
}
)
@@ -18,7 +18,7 @@ async function main() {
}
)

await waitFor(5000)
await waitFor(15000)
await stream.close()
}

@@ -8,7 +8,7 @@ async function main() {
})

const stream = await client.streamTransaction(
{ id: "d9e98cec9fcb5604da38ca250eb22246520bfeee2c35298032c2fbb825eb406d" },
{ id: "d2233029848840cc67c32a617b7339664a5866bf229a1833afccc3b4653f594a" },
(message: InboundMessage) => {
if (message.type !== InboundMessageType.TRANSACTION_LIFECYCLE) {
return
@@ -17,6 +17,7 @@ export * from "./types/action-trace"
export * from "./types/auth-token"
export * from "./types/block-id"
export * from "./types/client"
export * from "./types/common"
export * from "./types/error"
export * from "./types/head-info"
export * from "./types/http-client"
@@ -1,16 +1,15 @@
import { DbOp } from "./table-delta"
import { RAMOp, DTrxOp, TableOp } from "./transaction"
import { RamOp, DTrxOp, TableOp, Int64, Uint64 } from "./common"

export type ActionTraceData<T = Record<string, any>, D = Record<string, any>> = {
export type ActionTraceData<T = Record<string, any>> = {
block_num: number
block_id: string
block_time: string
trx_id: string
idx: number
depth: number
trace: ActionTrace<T>
dbops?: DbOp<D>[]
ramops?: RAMOp[]
dbops?: ActionTraceDbOp[]
ramops?: RamOp[]
dtrxops?: DTrxOp[]
tableops?: TableOp[]
}
@@ -59,21 +58,67 @@ export type AccountRamDelta = {
}

/**
* A `int64_t` natively in `nodeos` but can become a string when > 32 bits number
* due to how `nodeos` serialize number to JSON.
* The `dbops` array out of an [[ActionTraceData]] message is completely
* different than other [[DbOp]] found in dfuse API (like on [[TableDeltaData]]
* or [[TransactionLifecycle]]).
*
* This is like because JavaScript largest number possible is 53 bits large which
* make it impossible to hold a full `int64_t` type. To overcome that, `nodeos`
* will output a string when number is too large to preserve precision.
*/
export type Int64 = number | string

/**
* A `uint64_t` natively in `nodeos` but can become a string when > 32 bits number
* due to how `nodeos` serialize number to JSON.
* One for `opayer` or `npayer` will always be present depending on the
* operation, same thing for the `old` and `new` fields:
*
* - When `op == "INS"`, `npayer` and `new` are present
* - When `op == "UPD"`, `opayer`, `old`, `npayer` and `new` are present
* - When `op == "REM"`, `opayer` and `old` are present
*
* The `old` and `new` fields are the hexadecimal string encoded
* representing the row in binary format.
*
* Check the [Decode Hex Data using eosjs example](https://github.com/dfuse-io/example-eosjs-decode-hex)
* for a way to transform the hexadecimal string into a JSON
* structure representing the row.
*
* This is like because JavaScript largest number possible is 53 bits large which
* make it impossible to hold a full `uint64_t` type. To overcome that, `nodeos`
* will output a string when number is too large to preserve precision.
* @see https://github.com/dfuse-io/example-eosjs-decode-hex
*/
export type Uint64 = number | string
export type ActionTraceDbOp = {
op: "INS" | "UPD" | "REM"
action_idx: number

/**
* The account which was the old payer of the row. Present when `op == "UPD" | "REM"`.
*/
opayer?: string

/**
* The account which is the new payer of the row. Present when `op == "UPD" | "REM"`.
*/
npayer?: string

/**
* The full path of the database row, it's a string with four elements
* of the row path separated with the `/` character being respectively
* from left to right: account, scope, table, row primary key (name encoded).
*
* ```
* "eosio.token/trustdicewin/accounts/........ehbo5"
*
* {
* account: "eosio.token",
* scope: "trustdicewin",
* table: "accounts",
* key: "........ehbo5", // Name encoded value representing `EOS` SymbolCode
* }
* ```
*/
path: string

/**
* The hexadecimal string encoded representing the old version of the
* row in binary format. Present when `op == "UPD" | "REM"`.
*/
old?: string

/**
* The hexadecimal string encoded representing the new version of the
* row in binary format. Present when `op == "INS" | "UPD"`.
*/
new?: string
}
@@ -0,0 +1,101 @@
import { ErrorData } from "./error"
import { Transaction } from "./transaction"

/**
* A `int64_t` natively in `nodeos` but can become a string when > 32 bits number
* due to how `nodeos` serialize number to JSON.
*
* This is like because JavaScript largest number possible is 53 bits large which
* make it impossible to hold a full `int64_t` type. To overcome that, `nodeos`
* will output a string when number is too large to preserve precision.
*/
export type Int64 = number | string

/**
* A `uint64_t` natively in `nodeos` but can become a string when > 32 bits number
* due to how `nodeos` serialize number to JSON.
*
* This is like because JavaScript largest number possible is 53 bits large which
* make it impossible to hold a full `uint64_t` type. To overcome that, `nodeos`
* will output a string when number is too large to preserve precision.
*/
export type Uint64 = number | string

/**
* Represents a node in the creation tree.
* first number represents the creation node index
* second number represents the parent node index (-1 for root)
* third number represents the action index
*/
export type CreationNode = [number, number, number]

export type DTrxOp = {
op: "CREATE" | "PUSH_CREATE" | "MODIFY_CREATE" | "MODIFY_CANCEL" | "CANCEL"
action_idx: number
sender: string
sender_id: string
payer: string
published_at: string
delay_until: string
expiration_at: string
trx_id: string
trx?: Transaction
}

export type ExtDTrxOp = {
src_trx_id: string
block_num: number
block_id: string
block_time: string
} & DTrxOp

/**
* @deprecated Renamed to `DbOp`
*/
export type DBOp<T = unknown> = DbOp<T>

export type DbOp<T = unknown> = {
/**
* This is a quirk of dfuse API, it's recommended to do a lower case comparison on the `op` field.
*/
op: "ins" | "INS" | "upd" | "UPD" | "rem" | "REM"
action_idx: number
account: string
table: string
scope: string
key: string
old?: DbRow<T>
new?: DbRow<T>
}

/**
* One of `error`, `hex` or `json` field will be present depending
* on the actual request made.
*/
export type DbRow<T = unknown> = {
payer: string
blockNum?: string
error?: ErrorData
hex?: string
json?: T
}

export type RamOp = {
op: string
action_idx: number
payer: string
delta: number
usage: number
}

/**
* @deprecated Renamed to `RamOp`
*/
export type RAMOp = RamOp

export type TableOp = {
op: "INS" | "REM"
action_idx: number
payer: string
path: string
}

0 comments on commit 5002779

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