Skip to content

Latest commit

 

History

History
90 lines (76 loc) · 1.68 KB

File metadata and controls

90 lines (76 loc) · 1.68 KB

Blockchain Adapters

A blockchain adapter consists of several APIs that @tradle/engine calls for reading and writing blockchain seals: network, transactor, and blockchain.

Existing adapters:

Network

Pass in a network object when initializing a tradle node:

new tradle.node({
//  ...
  network: {
    blockchain: 'bitcoin',
    name: 'testnet',
    minOutputAmount: 547,
    pubKeyToAddress: Buffer => String
  }
// ...
})

Blockchain

new tradle.node({
//  ...
  blockchain: {
    transactions: {
      // fetch transactions by id
      get: function (txIds, cb) {
        // ...
        // see below for Transaction Object format
        cb(null, [txObjects])
      }
    },
    addresses: {
      // fetch transactions by to/from addresses
      transactions: function (addresses, [height], cb) {
        // ...
        // see below for Transaction Object format
        cb(null, [txObjects])
      }
    }
  }
// ...
})

Transaction Object

{
  blockHeight: Number,
  txId: String, // hex
  confirmations: Number,
  from: {
    addresses: [String, String, ...]
  },
  to: {
    addresses: [String, String, ...]
  }
}

Transactor

The transactor API is for writing blockchain seals. If you're running a read-only node, you can omit it.

new tradle.node({
//  ...
  transactor: {
    send: function (opts, cb) {
      console.log(opts)
      // array of output address and amount pairs
      // [{ address, amount }, ...]
      // ...
      // call back with the txId of the created transaction
      cb(null, { txId })
    }
  }
// ...
})