Skip to content

Updating dependencies to work with node 14 and for the tests to pass #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 33 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f1b7f77
chore: removing package-lock as this is a library not an app
martinheidegger Apr 18, 2022
1e7fea4
fix: using Buffer.from instead of deprecated new Buffer
martinheidegger Oct 30, 2021
4a1c54b
chore: using tradle wallet
martinheidegger Oct 30, 2021
1166091
chore: ethereumjs-testrpc is deprecated in favor of ganache-core
martinheidegger Oct 30, 2021
841e536
tests: Removing forever dependency as forever isn't maintained and 10…
martinheidegger Oct 30, 2021
a009cd1
chore: npm dependencies whenever ready.
martinheidegger Oct 30, 2021
5e2000c
chore: syntax cleanup
martinheidegger Jan 12, 2022
9ad27bb
tests: increasing timeouts
martinheidegger Jan 12, 2022
56e2e3b
tests: allowing DEBUG= environment variables in ethereum tests
martinheidegger Jan 12, 2022
356f0ca
tests: making sure t.end is called at the actual end
martinheidegger Jan 12, 2022
f5ec6ff
chore: run all tests without git and with the latest versions of tap …
martinheidegger Jan 12, 2022
33b01aa
chore: update dependencies
martinheidegger Jan 12, 2022
9a2e72f
refactor: controls as bitcoin fails in control system
martinheidegger Jan 12, 2022
082838a
tests: better fail error message
martinheidegger Jan 12, 2022
c623b90
chore: using @tradle namespaced changes-feed
martinheidegger Jan 19, 2022
3a39be0
fix: do not throw errors in methods with callbacks
martinheidegger Jan 19, 2022
d9ab7b3
tests: using ganache instead of ganache-core
martinheidegger Mar 16, 2022
8127c96
refactor: normalizing require statements
martinheidegger Mar 24, 2022
a2b2a69
chore: precompiling schema
martinheidegger Mar 24, 2022
b7d3e5e
refactor: using @tradle/typeforce instead of typeforce for types
martinheidegger Mar 25, 2022
54ac06e
chore: removing obsolete/unused fragments of text/code that isn't doi…
martinheidegger Mar 25, 2022
f652a50
fix: special characters in indentation
martinheidegger Mar 25, 2022
d5d1eb2
style: readability
martinheidegger Mar 25, 2022
66ac154
refactor: stop using extend as it will make code introspection hard/i…
martinheidegger Mar 25, 2022
187ff57
fix: added missing debug setting (prevents runtime error)
martinheidegger Mar 25, 2022
08d11f6
refactor: direct pass-in is faster and code introspection works bette…
martinheidegger Mar 25, 2022
2acf468
fix: otherAuthor is not a defined variable
martinheidegger Mar 25, 2022
a962087
fix: adding missing omit/pick utils
martinheidegger Mar 28, 2022
7f40a60
chore: grouping controls tests
martinheidegger Mar 28, 2022
5336294
refactor: using more appropriate find instead of .some and using alre…
martinheidegger Mar 28, 2022
6588690
scripts: always stop ether before starting, it may have crashed before
martinheidegger Mar 28, 2022
9875373
chore: updating dependencies
martinheidegger Mar 28, 2022
7d9e7dc
refactor: easier to turn into typescript
martinheidegger Apr 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ processed.txt
*.log
lite.js
test/sealer.test.js1
package-lock.json
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ addons:
packages:
- g++-4.8
install:
- "travis_retry npm i -g forever tap"
- "travis_retry npm i -g tap"
- "travis_retry npm i"
49 changes: 17 additions & 32 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,19 @@

const tradle = module.exports = exports
// tradle.keeper = require('./lib/keeper')
tradle.protocol = require('@tradle/protocol')
tradle.sender = require('./lib/sender')
tradle.sealer = require('./lib/sealer')
tradle.sealwatch = require('./lib/sealwatch')
tradle.dbs = {
objects: require('./lib/dbs/objects'),
// tx: require('./lib/dbs/txs'),
seals: require('./lib/dbs/seals'),
watches: require('./lib/dbs/watches'),
addressBook: require('./lib/dbs/addressBook'),
simpleCustom: require('./lib/dbs/simpleCustom'),
msgMeta: require('./lib/dbs/msgMeta'),
module.exports = {
constants: require('./lib/constants.js'),
dbs: require('./lib/dbs/index.js'),
errors: require('./lib/errors.js'),
node: require('./lib/node.js'),
partial: require('./lib/partial.js'),
protocol: require('@tradle/protocol'),
protobuf: require('./lib/proto.js'),
retrystream: require('./lib/retrystream.js'),
sender: require('./lib/sender.js'),
sealer: require('./lib/sealer.js'),
sealwatch: require('./lib/sealwatch.js'),
topics: require('./lib/topics.js'),
typeforce: require('@tradle/typeforce'),
types: require('./lib/types.js'),
utils: require('./lib/utils.js'),
validator: require('./lib/validator.js')
}

tradle.retrystream = require('./lib/retrystream')
tradle.validator = require('./lib/validator')
tradle.types = require('./lib/types')
tradle.utils = require('./lib/utils')
tradle.constants = require('./lib/constants')
// tradle.constants = {
// status: require('./lib/status'),
// topics: require('./lib/topics')
// }

tradle.topics = require('./lib/topics')
tradle.protobuf = require('./lib/proto')
tradle.node = require('./lib/node')
tradle.partial = require('./lib/partial')

tradle.typeforce = require('./lib/typeforce')
tradle.errors = require('./lib/errors')
198 changes: 88 additions & 110 deletions lib/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

const EventEmitter = require('events').EventEmitter
const debug = require('debug')('tradle:actions')
const protocol = require('@tradle/protocol')
const typeforce = require('./typeforce')
const typeforce = require('@tradle/typeforce')
const statuses = require('./status')
const SealStatus = statuses.seal
const { TYPES, TYPE, SEQ } = require('./constants')
const { PARTIAL, MESSAGE } = TYPES
const { MESSAGE } = TYPES
const types = require('./types')
const topics = require('./topics')
const utils = require('./utils')
Expand All @@ -24,23 +23,81 @@ const WROTE_SEAL_COPY_PROPS = [
'status'
]

// const WRITE_SEAL_ACTION_PROPS = [
// 'basePubKey',
// 'link',
// 'prevLink',
// 'headerHash',
// 'prevHeaderHash',
// 'sealAddress',
// 'sealPrevAddress',
// 'blockchain',
// 'networkName',
// 'amount'
// ]

/**
* @typedef {Object} Actions
*/

const actionOpts = typeforce.compile({
changes: types.changes,
node: typeforce.maybe(typeforce.Object)
// other env vars like networkName
})

const wroteSealData = typeforce.compile({
link: typeforce.String,
sealAddress: typeforce.String,
blockchain: typeforce.String,
networkName: typeforce.String
})

const createWatchWatch = typeforce.compile({
blockchain: typeforce.String,
networkName: typeforce.String,
address: typeforce.String,
link: typeforce.String,
headerHash: typeforce.String,
basePubKey: types.chainPubKey,
watchType: typeforce.String,
txId: typeforce.maybe(typeforce.String)
})

const wroteSealTx = typeforce.compile({
txId: typeforce.String
})

const createObjectWrapper = typeforce.compile({
object: types.signedObject,
link: typeforce.String,
author: typeforce.String,
permalink: typeforce.maybe(typeforce.String),
prevLink: typeforce.maybe(typeforce.String),
objectinfo: typeforce.maybe(typeforce.Object),
partialinfo: typeforce.maybe(typeforce.Object)
})

const writeSealData = typeforce.compile({
link: typeforce.String,
headerHash: typeforce.String,
blockchain: typeforce.String,
networkName: typeforce.String,
basePubKey: types.chainPubKey,
sealPubKey: types.chainPubKey,
prevLink: typeforce.maybe(typeforce.String),
prevHeaderHash: typeforce.maybe(typeforce.String),
sealPrevPubKey: typeforce.maybe(types.chainPubKey),
sealAddress: typeforce.maybe(typeforce.String),
sealPrevAddress: typeforce.maybe(typeforce.String),
amount: typeforce.maybe(typeforce.Number)
})

const readSealData = typeforce.compile({
blockchain: typeforce.String,
networkName: typeforce.String,
link: typeforce.maybe(typeforce.String),
prevLink: typeforce.maybe(typeforce.String),
headerHash: typeforce.maybe(typeforce.String),
prevHeaderHash: typeforce.maybe(typeforce.String),
basePubKey: types.chainPubKey,
txId: typeforce.String,
confirmations: typeforce.Number,
addresses: typeforce.arrayOf(typeforce.String),
// if we know sealAddress, we already know what version we're monitoring
sealAddress: typeforce.maybe(typeforce.String),
// if we only know sealPrevAddress, we've detected a seal for a version
// we do not yet possess
sealPrevAddress: typeforce.maybe(typeforce.String),
})

/**
* actions
* @alias module:actions
Expand All @@ -49,29 +106,17 @@ const WROTE_SEAL_COPY_PROPS = [
* @param {node} [opts.node]
*/
module.exports = function (opts) {
typeforce({
changes: types.changes,
node: typeforce.maybe(typeforce.Object)
// other env vars like networkName
}, opts)
actionOpts.assert(opts)

const node = opts.node
const changes = opts.changes

function wroteSeal (data, tx, cb) {
typeforce({
link: typeforce.String,
sealAddress: typeforce.String,
blockchain: typeforce.String,
networkName: typeforce.String
}, data)

typeforce({
txId: typeforce.String
}, tx)
wroteSealData.assert(data)
wroteSealTx.assert(tx)

if ((data.prevLink || data.sealPrevAddress) && !(data.prevLink && data.sealPrevAddress)) {
throw new Error('expected either both prevLink and sealPrevAddress or neither')
return cb(new Error('expected either both prevLink and sealPrevAddress or neither'))
}

const action = utils.pick(data, WROTE_SEAL_COPY_PROPS)
Expand All @@ -82,8 +127,8 @@ module.exports = function (opts) {
}

function addContact (identity, link, cb) {
typeforce(types.identity, identity)
typeforce(typeforce.String, link)
types.identity.assert(identity)
typeforce.String.assert(link)

const entry = utils.getLinks({
link,
Expand All @@ -95,15 +140,7 @@ module.exports = function (opts) {
}

function createObject (wrapper, cb) {
typeforce({
object: types.signedObject,
link: typeforce.String,
author: typeforce.String,
permalink: typeforce.maybe(typeforce.String),
prevLink: typeforce.maybe(typeforce.String),
objectinfo: typeforce.maybe(typeforce.Object),
partialinfo: typeforce.maybe(typeforce.Object)
}, wrapper)
createObjectWrapper.assert(wrapper)

const entry = utils.pick(wrapper, 'link', 'permalink', 'prevLink', 'author', 'recipient', 'objectinfo', 'partialinfo')
utils.addLinks(entry)
Expand All @@ -112,7 +149,7 @@ module.exports = function (opts) {
if (entry.type === MESSAGE) {
entry.seq = wrapper.object[SEQ]
entry.timestamp = wrapper.object._time
typeforce(typeforce.String, entry.recipient)
typeforce.String.assert(entry.recipient)
if (!wrapper.received) {
entry.sendstatus = statuses.send.pending
}
Expand All @@ -132,20 +169,8 @@ module.exports = function (opts) {
}

function writeSeal (data, cb) {
typeforce({
link: typeforce.String,
headerHash: typeforce.String,
blockchain: typeforce.String,
networkName: typeforce.String,
basePubKey: types.chainPubKey,
sealPubKey: types.chainPubKey,
prevLink: typeforce.maybe(typeforce.String),
prevHeaderHash: typeforce.maybe(typeforce.String),
sealPrevPubKey: typeforce.maybe(types.chainPubKey),
sealAddress: typeforce.maybe(typeforce.String),
sealPrevAddress: typeforce.maybe(typeforce.String),
amount: typeforce.maybe(typeforce.Number)
}, data, true)
writeSealData.assert(data, true)


data.topic = topics.queueseal
if (!data.sealAddress) {
Expand All @@ -161,48 +186,19 @@ module.exports = function (opts) {
}

data.status = SealStatus.pending
// data.uid = getSealUID(data)
data.write = true
append(data, cb)
}

function createWatch (watch, cb) {
typeforce({
blockchain: typeforce.String,
networkName: typeforce.String,
address: typeforce.String,
link: typeforce.String,
headerHash: typeforce.String,
basePubKey: types.chainPubKey,
watchType: typeforce.String,
txId: typeforce.maybe(typeforce.String)
}, watch, true)
createWatchWatch.assert(watch, true)

watch.topic = topics.newwatch
append(watch, cb)
}

// function saveTx (txInfo, cb) {
// typeforce({
// txId: typeforce.String,
// txHex: typeforce.String,
// tx: typeforce.Object,
// from: typeforce.Object,
// to: typeforce.Object,
// confirmations: typeforce.Number,
// }, txInfo)

// append({
// topic: topics.tx,
// txHex: txInfo.txHex,
// from: txInfo.from,
// to: txInfo.to,
// confirmations: txInfo.confirmations,
// }, cb)
// }

function sentMessage (link, cb) {
typeforce(typeforce.String, link)
typeforce.String.assert(link)

append({
topic: topics.sent,
Expand All @@ -212,7 +208,7 @@ module.exports = function (opts) {
}

function abortMessage (link, cb) {
typeforce(typeforce.String, link)
typeforce.String.assert(link)

append({
topic: topics.sendaborted,
Expand All @@ -222,23 +218,7 @@ module.exports = function (opts) {
}

function readSeal (data, cb) {
typeforce({
blockchain: typeforce.String,
networkName: typeforce.String,
link: typeforce.maybe(typeforce.String),
prevLink: typeforce.maybe(typeforce.String),
headerHash: typeforce.maybe(typeforce.String),
prevHeaderHash: typeforce.maybe(typeforce.String),
basePubKey: types.chainPubKey,
txId: typeforce.String,
confirmations: typeforce.Number,
addresses: typeforce.arrayOf(typeforce.String),
// if we know sealAddress, we already know what version we're monitoring
sealAddress: typeforce.maybe(typeforce.String),
// if we only know sealPrevAddress, we've detected a seal for a version
// we do not yet possess
sealPrevAddress: typeforce.maybe(typeforce.String),
}, data, true)
readSealData.assert(data, true)

if (!(data.sealAddress || data.sealPrevAddress)) {
throw new Error('expected "sealAddress" or "sealPrevAddress"')
Expand All @@ -248,7 +228,6 @@ module.exports = function (opts) {
throw new Error('expected "headerHash" or "prevHeaderHash"')
}

// data.confirmed = data.confirmations >= node.confirmedAfter
data.topic = topics.readseal
append(data, cb)
}
Expand All @@ -270,7 +249,7 @@ module.exports = function (opts) {
function append (entry, cb) {
cb = cb || noop

typeforce(typeforce.String, entry.topic)
typeforce.String.assert(entry.topic)

entry.timestamp = entry.timestamp || utils.now()
changes.append(entry, function (err) {
Expand All @@ -295,7 +274,6 @@ module.exports = function (opts) {
createObject,
writeSeal,
createWatch,
// saveTx,
readSeal,
forgetObject,
rememberObject
Expand Down
Loading