Skip to content

Refactor Socket Connection

Compare
Choose a tag to compare
@lnbc1QWFyb24 lnbc1QWFyb24 released this 25 Mar 04:23
· 236 commits to master since this release
d8a37ce

This is a major release with breaking changes that include:

  • An architecture change that creates a separate WebSocket connection for each instance of the SDK that is running in the same client and ensures completely separate state between instances
  • Removal of the clientIndex parameter from the API and also removing it from calls to account, transaction and unsubscribe for a better dev experience.

Changes you need to make when upgrading from 1.x.x to 2.0.0:

  • The SDK is now created from a class instead of a function, requiring the new keyword when instantiating:
// 1.x.x
import blocknativeSdk from 'bnc-sdk'
const blocknative = blocknativeSdk(options)

// 2.0.0
import BlocknativeSdk from 'bnc-sdk'
const blocknative = new BlocknativeSdk(options)
  • The clientIndex parameter has been removed from the API and doesn't need to be included in function calls:
// === watching a transaction === //
// 1.x.x
const { emitter } = blocknative.transaction(blocknative.clientIndex, hash)
// 2.0.0
const { emitter } = blocknative.transaction(hash)

// === watching a account === //
// 1.x.x
const { emitter } = blocknative.account(blocknative.clientIndex, address)
// 2.0.0
const { emitter } = blocknative.account(address)

// === unwatching a transaction === //
// 1.x.x
const { emitter } = blocknative.unsubscribe(blocknative.clientIndex, hash)
// 2.0.0
const { emitter } = blocknative.unsubscribe(hash)

// === unwatching a account === //
// 1.x.x
const { emitter } = blocknative.unsubscribe(blocknative.clientIndex, address)
// 2.0.0
const { emitter } = blocknative.unsubscribe(address)

Changelog:

  • Feature: refactor connection (#46)
  • Bump acorn from 5.7.3 to 5.7.4 (#44)