-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from plasma-group/dev-state-update
Update how we represent state to match spec
- Loading branch information
Showing
6 changed files
with
117 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
export * from './src/constants' | ||
export * from './src/state-object' | ||
export * from './src/sum-tree' | ||
export * from './src/transaction' | ||
export * from './src/utils' | ||
export * from './src/state' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './state-object' | ||
export * from './state-update' | ||
export * from './transaction' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* Internal Imports */ | ||
import { abi } from '../utils' | ||
|
||
const STATE_OBJECT_ABI_TYPES = ['address', 'bytes'] | ||
|
||
export interface StateObjectData { | ||
predicate: string | ||
parameters: string | ||
} | ||
|
||
/** | ||
* Class that represents a simple state object. | ||
* State objects are the fundamental building | ||
* blocks of our plasma chain design. | ||
*/ | ||
export class StateObject { | ||
public predicate: string | ||
public parameters: string | ||
|
||
constructor(args: StateObjectData) { | ||
this.predicate = args.predicate | ||
this.parameters = args.parameters | ||
} | ||
|
||
/** | ||
* @returns the encoded state object. | ||
*/ | ||
get encoded(): string { | ||
return abi.encode(STATE_OBJECT_ABI_TYPES, [this.predicate, this.parameters]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* External Imports */ | ||
import BigNum = require('bn.js') | ||
|
||
/* Internal Imports */ | ||
import { abi } from '../utils' | ||
import { StateObject } from './state-object' | ||
|
||
const STATE_OBJECT_ABI_TYPES = [ | ||
'uint256', | ||
'uint256', | ||
'uint256', | ||
'bytes', | ||
'bytes', | ||
] | ||
|
||
interface StateUpdateArgs { | ||
start: number | BigNum | ||
end: number | BigNum | ||
block: number | BigNum | ||
plasmaContract: string | ||
newState: StateObject | ||
} | ||
|
||
/** | ||
* Represents a StateUpdate, which wraps each state | ||
* update but doesn't have a witness. | ||
*/ | ||
export class StateUpdate { | ||
public start: BigNum | ||
public end: BigNum | ||
public block: BigNum | ||
public plasmaContract: string | ||
public newState: StateObject | ||
|
||
constructor(args: StateUpdateArgs) { | ||
this.start = new BigNum(args.start, 'hex') | ||
this.end = new BigNum(args.end, 'hex') | ||
this.block = new BigNum(args.block, 'hex') | ||
this.plasmaContract = args.plasmaContract | ||
this.newState = args.newState | ||
} | ||
|
||
/** | ||
* @returns the encoded state update. | ||
*/ | ||
get encoded(): string { | ||
return abi.encode(STATE_OBJECT_ABI_TYPES, [ | ||
this.start, | ||
this.end, | ||
this.block, | ||
this.plasmaContract, | ||
this.newState.encoded, | ||
]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters