-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Contract and ActionWrapper helpers
- Loading branch information
Showing
15 changed files
with
126 additions
and
163 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { PermissionLevel, Action } from "./action" | ||
import { MultiIndexValue } from "./mi" | ||
import { Name } from "./name" | ||
|
||
export class ActionWrapperAct { | ||
constructor( | ||
public action: Name, | ||
public contract: Name, | ||
public permissionLevel: PermissionLevel | ||
){} | ||
|
||
send <T extends MultiIndexValue>(data: T): void { | ||
const permissions = [this.permissionLevel] | ||
const action = new Action(permissions, this.contract, this.action, data.pack()) | ||
action.send() | ||
} | ||
} | ||
|
||
export class ActionWrapper { | ||
public action: Name | ||
constructor(action: string){ | ||
this.action = Name.fromString(action) | ||
} | ||
|
||
/** | ||
* Create an action with act given contract, actor, and permission | ||
* @param {Name} contract - The name of the contract | ||
* @param {Name} actor - The name of the account that is executing the contract. | ||
* @param {string} permission - The permission that the actor must have to execute the contract. | ||
* @returns An instance of the Act class. | ||
*/ | ||
act ( | ||
contract: Name, | ||
permissionLevel: PermissionLevel | ||
): ActionWrapperAct { | ||
return new ActionWrapperAct(this.action, contract, permissionLevel) | ||
} | ||
} | ||
|
||
export class Contract { | ||
constructor( | ||
public receiver: Name, | ||
public firstReceiver: Name, | ||
public action: Name | ||
) {} | ||
} |
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
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
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.