Skip to content

Commit

Permalink
Pushing dependency fixes to be able to build master (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
willmeister authored and smartcontracts committed Jun 10, 2019
1 parent b031ec4 commit ce9e49a
Show file tree
Hide file tree
Showing 14 changed files with 127 additions and 210 deletions.
1 change: 1 addition & 0 deletions packages/predicates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
"devDependencies": {
"@pigi/prettier-config": "^0.0.2-alpha.2",
"@pigi/utils": "^0.0.1-alpha.2",
"@types/chai": "^4.1.7",
"@types/debug": "^4.1.2",
"@types/mocha": "^5.2.6",
Expand Down
1 change: 1 addition & 0 deletions packages/utils/src/data-types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './state-object'
51 changes: 51 additions & 0 deletions packages/utils/src/data-types/state-object.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* Internal Imports */
import { abi } from '../eth'
import { StateObject, AbiEncodable } from '../interfaces/data-types'

/**
* Creates a StateObject from an encoded StateObject.
* @param encoded The encoded StateObject.
* @returns the StateObject.
*/
const fromEncoded = (encoded: string): AbiStateObject => {
const decoded = abi.decode(AbiStateObject.abiTypes, encoded)
return new AbiStateObject(
decoded[0],
decoded[1]
)
}

/**
* Represents a basic abi encodable StateObject
*/
export class AbiStateObject implements StateObject, AbiEncodable {
public static abiTypes = ['address', 'bytes']

constructor(
readonly predicateAddress: string,
readonly data: string,
) {}

/**
* @returns the abi encoded StateObject.
*/
get encoded(): string {
return abi.encode(AbiStateObject.abiTypes, [
this.predicateAddress,
this.data
])
}

/**
* Casts a value to a StateObject.
* @param value Thing to cast to a StateObject.
* @returns the StateObject.
*/
public static from(value: string): AbiStateObject {
if (typeof value === 'string') {
return fromEncoded(value)
}

throw new Error('Got invalid argument type when casting to StateObject.')
}
}
2 changes: 2 additions & 0 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export * from './utils'
export * from './constants'
export * from './eth'
export * from './sum-tree'
export * from './interfaces'
export * from './data-types'
37 changes: 37 additions & 0 deletions packages/utils/src/interfaces/data-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import BigNum = require('bn.js')

export interface Range {
start: BigNum
end: BigNum
}

export interface EcdsaSignature {
v: string
r: string
s: string
}

export interface AbiEncodable {
encoded: string
}

export interface Transaction {
plasmaContract: string
block: number
range: Range
methodId: string
parameters: any
witness: any
}

export interface StateObject {
predicateAddress: string,
data: any
}

export interface StateUpdate {
stateObject: StateObject,
range: Range,
blockNumber: number,
plasmaContract: string
}
1 change: 1 addition & 0 deletions packages/utils/src/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './data-types'
5 changes: 3 additions & 2 deletions packages/watch-eth/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export { EventWatcher, EventWatcherOptions } from './src/event-watcher'
export { EventLog, EventFilter } from './src/models'
export { DefaultEventLog, EventFilter } from './src/models'
export {
EventDB,
EthProvider,
FullEventFilter,
EventFilterOptions
EventFilterOptions,
EventLog
} from './src/interfaces'
6 changes: 3 additions & 3 deletions packages/watch-eth/src/eth-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import Web3 from 'web3'

/* Internal Imports */
import { EthProvider, FullEventFilter } from './interfaces'
import { EventLog } from '../models'
import { EthProvider, FullEventFilter, EventLog } from './interfaces'
import { DefaultEventLog } from './models'


/**
Expand Down Expand Up @@ -45,7 +45,7 @@ export class DefaultEthProvider implements EthProvider {
toBlock: filter.toBlock,
} as any)
return events.map((event) => {
return new EventLog(event)
return new DefaultEventLog(event)
})
}
}
14 changes: 7 additions & 7 deletions packages/watch-eth/src/event-watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const Web3 = require('web3') // tslint:disable-line

/* Internal Imports */
import { sleep } from './utils'
import { EventFilter, EventLog } from './models'
import { EventDB, EthProvider } from './interfaces'
import { EventFilter, DefaultEventLog } from './models'
import { EventDB, EthProvider, EventFilterOptions, EventLog } from './interfaces'
import { DefaultEventDB } from './event-db'
import { DefaultEthProvider } from './eth-provider'

Expand Down Expand Up @@ -36,8 +36,8 @@ const defaultOptions = {
*/
export class EventWatcher extends EventEmitter {
private options: EventWatcherOptions
private eth: BaseEthProvider
private db: BaseEventDB
private eth: EthProvider
private db: EventDB
private polling = false
private subscriptions: { [key: string]: EventSubscription } = {}

Expand Down Expand Up @@ -238,15 +238,15 @@ export class EventWatcher extends EventEmitter {
return (
index ===
self.findIndex((e) => {
return e.hash === event.hash
return e.getHash() === event.getHash()
})
)
})

// Filter out events we've already seen.
const isUnique = await Promise.all(
events.map(async (event) => {
return !(await this.db.getEventSeen(event.hash))
return !(await this.db.getEventSeen(event.getHash()))
})
)
return events.filter((_, i) => isUnique[i])
Expand All @@ -268,7 +268,7 @@ export class EventWatcher extends EventEmitter {

// Mark these events as seen.
for (const event of events) {
await this.db.setEventSeen(event.hash)
await this.db.setEventSeen(event.getHash())
}

// Alert any listeners.
Expand Down
3 changes: 2 additions & 1 deletion packages/watch-eth/src/interfaces/eth-provider.interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* Internal Imports */
import { EventFilterOptions } from './event-filter'
import { EventFilterOptions } from './event-filter-options.interface'
import { EventLog } from './event-log.interface'

export interface FullEventFilter extends EventFilterOptions {
address: string
Expand Down
6 changes: 6 additions & 0 deletions packages/watch-eth/src/interfaces/event-log.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {EventLogData} from "./event-log-data.interface";

export interface EventLog {
data: EventLogData
getHash(): string
}
1 change: 1 addition & 0 deletions packages/watch-eth/src/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './event-filter-options.interface'
export * from './eth-provider.interface'
export * from './event-log-data.interface'
export * from './event-log.interface'
export * from './event-db.interface'
6 changes: 3 additions & 3 deletions packages/watch-eth/src/models/event-log.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* Internal Imports */
import { hash } from '../utils'
import { EventLogData } from '../interfaces'
import { EventLog, EventLogData } from '../interfaces'


/**
* Represents a single event log.
*/
export class EventLog {
export class DefaultEventLog implements EventLog {
public data: EventLogData

constructor(data: EventLogData) {
Expand All @@ -16,7 +16,7 @@ export class EventLog {
/**
* Returns a unique hash for this event log.
*/
get hash(): string {
getHash(): string {
return hash(this.data.transactionHash + this.data.logIndex)
}
}

0 comments on commit ce9e49a

Please sign in to comment.