-
Notifications
You must be signed in to change notification settings - Fork 106
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 #2401 from dedis/js-cothority-arrange
@cothority/byzcoin meaningful instruction print
- Loading branch information
Showing
9 changed files
with
274 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,67 @@ | ||
import { Darc } from "../../darc"; | ||
import { Roster } from "../../network"; | ||
import { Argument } from "../index"; | ||
import { ChainConfig } from "../index"; | ||
import { IBeautifyArgument } from "./utils"; | ||
// tslint:disable-next-line | ||
const varint = require("varint"); | ||
|
||
/** | ||
* Arrange arguments for a config contract, ie. provide a meaningful | ||
* representation of its arguments. | ||
*/ | ||
export class ConfigBeautifier { | ||
static Spawn(args: Argument[]): IBeautifyArgument[] { | ||
const res = Array<IBeautifyArgument>(); | ||
|
||
args.forEach((arg) => { | ||
switch (arg.name) { | ||
case "darc": | ||
const darc = Darc.decode(arg.value); | ||
res.push({name: "darc", value: darc.description.toString(), full: darc.toString()}); | ||
break; | ||
case "block_interval": | ||
res.push({name: "block_interval", value: `${varint.decode(arg.value, 0) / 1e6} ms`}); | ||
break; | ||
case "max_block_size": | ||
res.push({name: "max_block_size", value: `${varint.decode(arg.value, 0)} bytes`}); | ||
break; | ||
case "roster": | ||
const r = Roster.decode(arg.value); | ||
res.push({name: "roster", value: r.id.toString("hex"), full: r.toTOML()}); | ||
break; | ||
case "trie_nonce": | ||
res.push({name: "trie_nonce", value: `${varint.decode(arg.value, 0)}`}); | ||
break; | ||
case "darc_contracts": | ||
res.push({name: "darc_contracts", value: arg.value.toString("hex")}); | ||
break; | ||
default: | ||
res.push({name: arg.name, value: "unspecified", full: arg.value.toString("hex")}); | ||
break; | ||
} | ||
}); | ||
|
||
return res; | ||
} | ||
|
||
static Invoke(args: Argument[]): IBeautifyArgument[] { | ||
const res = Array<IBeautifyArgument>(); | ||
|
||
args.forEach((arg) => { | ||
switch (arg.name) { | ||
case "config": | ||
// Calypso tests won't pass if we use ChainConfig. | ||
// const config = ChainConfig.decode(arg.value); | ||
// res.push({name: "darc", value: "chain config", full: config.toString()}); | ||
res.push({name: "darc", value: "chain config"}); | ||
break; | ||
default: | ||
res.push({name: arg.name, value: "unspecified", full: arg.value.toString("hex")}); | ||
break; | ||
} | ||
}); | ||
|
||
return res; | ||
} | ||
} |
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,45 @@ | ||
import { Darc as d } from "../../darc"; | ||
import { Roster } from "../../network"; | ||
import { Argument } from "../index"; | ||
import { IBeautifyArgument } from "./utils"; | ||
|
||
/** | ||
* Arrange arguments for a Darc contract, ie. provide a meaningful | ||
* representation of its arguments. | ||
*/ | ||
export class DarcBeautifier { | ||
static Spawn(args: Argument[]): IBeautifyArgument[] { | ||
const res = Array<IBeautifyArgument>(); | ||
|
||
args.forEach((arg) => { | ||
switch (arg.name) { | ||
case "darc": | ||
const darc = d.decode(arg.value); | ||
res.push({name: "darc", value: darc.description.toString(), full: darc.toString()}); | ||
break; | ||
default: | ||
res.push({name: arg.name, value: "unspecified", full: arg.value.toString("hex")}); | ||
break; | ||
} | ||
}); | ||
|
||
return res; | ||
} | ||
static Invoke(args: Argument[]): IBeautifyArgument[] { | ||
const res = Array<IBeautifyArgument>(); | ||
|
||
args.forEach((arg) => { | ||
switch (arg.name) { | ||
case "darc": | ||
const darc = d.decode(arg.value); | ||
res.push({name: "darc", value: darc.description.toString(), full: darc.toString()}); | ||
break; | ||
default: | ||
res.push({name: arg.name, value: "unspecified", full: arg.value.toString("hex")}); | ||
break; | ||
} | ||
}); | ||
|
||
return res; | ||
} | ||
} |
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,17 @@ | ||
import { Argument } from "../index"; | ||
import { IBeautifyArgument } from "./utils"; | ||
|
||
/** | ||
* Default representation of arguments | ||
*/ | ||
export class DefaultBeautifier { | ||
static Hex(args: Argument[]): IBeautifyArgument[] { | ||
const res = Array<IBeautifyArgument>(); | ||
|
||
args.forEach((arg) => { | ||
res.push({name: arg.name, value: arg.value.toString("hex")}); | ||
}); | ||
|
||
return res; | ||
} | ||
} |
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,12 @@ | ||
import { ConfigBeautifier } from "./config"; | ||
import { DarcBeautifier } from "./darc"; | ||
import { DefaultBeautifier } from "./default"; | ||
import { IBeautifierSchema, IBeautifyArgument } from "./utils"; | ||
|
||
export { | ||
DefaultBeautifier, | ||
DarcBeautifier, | ||
ConfigBeautifier, | ||
IBeautifierSchema, | ||
IBeautifyArgument, | ||
}; |
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,14 @@ | ||
import { Argument } from "../index"; | ||
|
||
export interface IBeautifierSchema { | ||
status: 0 | 1; | ||
type: "spawn" | "invoke" | "delete"; | ||
contract: string; | ||
args: IBeautifyArgument[]; | ||
} | ||
|
||
export interface IBeautifyArgument { | ||
name: string; | ||
value: string; | ||
full?: string; | ||
} |
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