Skip to content

Instantly share code, notes, and snippets.

@developerfred
Last active June 11, 2020 16:44
Show Gist options
  • Select an option

  • Save developerfred/4500720ff10829a80bde4f2c4e6d0e60 to your computer and use it in GitHub Desktop.

Select an option

Save developerfred/4500720ff10829a80bde4f2c4e6d0e60 to your computer and use it in GitHub Desktop.
Plasm Network Doc - Source Code
// Commitment storage: Plapps address => Commitment Child Storage.
Commitment get(fn commitment): T::AccountId => Commitment;
decl_child_storage! {
Commitment {
// Single operator address: OperatorId
OperatorAddress get(fn operator_address): T::AccountId;
// Current block number of commitment chain: BlockNumber
CurrentBlock get(fn current_block): T::BlockNumber;
// History of Merkle Root
Blocks get(fn blocks): map u128 => T::Hash
}
}
/// During the dispute period defined here, the user can challenge. If nothing is found, the state is determined after the dispute period.
type DISPUTE_PERIOD: T::Moment = 7;
// Event definitions (AccountID: PlappsAddress, BlockNumber, Hash: root)
BlockSubmitted(AccountId, BlockNumber, Hash);
// (checkpointId: Hash, checkpoint: Checkpoint);
CheckpointFinalized(Hash, Checkpoint);
// (exit_id: Hash)
ExitFinalized(Hash);
// (new_range: Range)
DepositedRangeExtended(Range);
// (removed_range: Range)
DepositedRangeRemoved(Range);
// (predicate_address: AccountId);
DeployPredicate(AccountId);
// (gameId: Hash, decision: bool)
AtomicPropositionDecided(Hash, bool);
// (game_id: Hash, property: Property, createdBlock: BlockNumber)
NewPropertyClaimed(Hash, Property, BlockNumber);
// (game_id: Hash, challengeGameId: Hash)
ClaimChallenged(Hash, Hash);
// (game_id: Hash, decision: bool)
ClaimDecided(Hash, bool);
// (game_id: Hash, challengeGameId: Hash)
ChallengeRemoved(Hash, Hash);
decl_modules! {
fn deposit(amount: T::Balance, initial_state: T::Property);
fn extend_deposited_ranges(amount: T::Balance);
fn remove_deposited_range(range: T::Range, depositedRangeId: T::Balance);
fn finalize_check_point(checkpoint_property: T::Property);
fn finalizeExit(exit_property: T::Property, deposited_range_id: T::Balance);
/// callable
fn is_subrange(subrange: T::Range, surroundingRange T::Range);
}
fn decide_true(predicate_address: T::AccountId, inputs: Vec<u8>, witness: Vec<u8>);
/// callable
fn is_valid_challenge(predicate_address: T::AccountId, inputs: Vec<u8>, challenge_inputs: Vec<u8>, challenge: T::Property);
fn decide(predicate_addres: T::AccountId, inputs: Vec<u8>, witness: Vec<u8>);
decl_storage! {
fn deploy(predicate: T::Predicate);
fn claim_property(claim: T::Property);
fn decide_claim_to_true(game_id: T::Hash);
fn decide_claim_to_false(game_id: T::Hash, challenging_game_id: T::Hash);
fn remove_challenge(game_id: T::Hash, challenging_game_id: T::Hash);
fn set_predicate_decision(game_id: T::Hash, decision: bool);
/**
* @dev challenge a game specified by gameId with a challengingGame specified by _challengingGameId
* @param _gameId challenged game id
* @param _challengeInputs array of input to verify child of game tree
* @param _challengingGameId child of game tree
*/
fn challenge(game_id: T::Hash, challenge_inputs: Vec<u8>, challenging_game_id);
/// callable
fn is_decided(property: T::Property);
fn get_game(claim_id: T::Hash);
fn get_property_id(property: T::Property);
}
decl_modules! {
fn submitRoot(blk_number: u64, root: T::Hash);
/**
* verifyInclusion method verifies inclusion of message in Double Layer Tree.
* The message has range and token address and these also must be verified.
* Please see https://docs.plasma.group/projects/spec/en/latest/src/01-core/double-layer-tree.html for further details.
* @param _leaf a message to verify its inclusion
* @param _tokenAddress token address of the message
* @param _range range of the message
* @param _inclusionProof The proof data to verify inclusion
* @param _blkNumber block number where the Merkle root is stored
*/
fn verifyInclusion(leaf: T::Hash, address, T::AccountId, range: T::Range, inclusionProof: InclusionProof, blk_number);
}
/// Commitment constructor + Deposit constructor
fn deploy(
aggregator_address: T::AccountId,
erc20: T::AccountId,
state_update_predicate: T::AccountId);
pub struct Predicate(Vec<u8>);
pub struct Property<AccountId> {
predicate_address: AccountId,
// Every input are bytes. Each Atomic Predicate decode inputs to the specific type.
inputs: Vec<u8>,
}
pub enum Decision {
Undecided,
True,
False
}
pub struct ChallengeGame<AccountId, BlockNumber> {
property: Property<AccountId>,
challenges: Vec<u8>,
decision: Decision,
created_block: BlockNumber,
}
pub struct Range<Balance> {
start: Balance,
end: Balance,
}
pub struct StateUpdate<AccountId, Balance, BlockNumber> {
deposit_contract_address: AccountId,
ragne: Range<Balance>,
block_number: BlockNumber,
state_object: Property<AccountId>,
}
pub struct Checkpoint<AccountId, Balance> {
subsrange: Range<Balance>,
state_update: Property<AccountId>,
}
pub struct Exit<AccountId, Range, BlockNumber, Property, Balance, Index> {
state_update: StateUpdate<AccountId, Range, BlockNumber, Property>,
inclusion_proof: InclusionProof<AccountId, Balance, Index>
}
pub struct InclusionProof<AccountId, Balance, Index> {
address_inclusion_proof: AddressInclusionProof<AccountId, Index>
interval_inclusion_proof: IntervalInclusionProof<Balance, Index>,
}
pub struct IntervalInclusionProof<Balance, Index> {
leaf_index: Index,
leaf_position: Index,
sibilings: Vec<IntervalTreeNode<Balance>>
}
pub struct AddressInclusionProof<AccountId, Index> {
leaf_index: AccountId,
leaf_position: Index,
siblings: Vec<AddressTreeNode<AccountId>>,
}
pub struct IntervalTreeNode<Balance> {
data: Vec<u8>,
start: Balance,
}
pub struct AddressTreeNode<AccountId> {
data: Vec<u8>,
token_address: AccountId,
}
// Deposit storage: Plapps address => Deposit Child Storage.
Deposit get(fn deposit): T::AccountId => Deposit;
decl_child_storage! {
Commitment {
ERC20 get(fn erc20): T::AccountId;
CommitmentContract get(fn commitment_contract): T::AccountId;
UniversalAdjudicatinonContract get(fn universalAdjudicationContract);
StateUpdatePredicate get(fn state_update_predicate): T::AccountId;
TotalDeposited get(fn total_deposited): T::Balance;
DepositedRanges get(fn deposited_ranges): map T::Balance => T::Range;
Checkpoints get(fn checkpoints): map T::Hash => T::Checkpoint;
}
}
/// predicate address => payout address
PayoutContractAddress get(fn payout_contract_address): map T::AccountId => T::AccountId;
decl_storage! {
Predicate get(fn predicate): map T::AccountId => T::Predicate;
DisputePeriod get(fn dispute_period): T::Moment;
InstantiatedGames get(fn instantiated_games): map T::Hash => T::ChallengeGame;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment