Skip to content

Commit

Permalink
Merge pull request #8 from SutuLabs/chore_import
Browse files Browse the repository at this point in the history
imported clawback relative clsp
  • Loading branch information
wizicer authored May 4, 2023
2 parents 214c40b + 95d3ca2 commit d9d6ce0
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 23 deletions.
42 changes: 23 additions & 19 deletions packages/cli/importmods.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,28 @@
import { readdirSync, readFileSync, writeFileSync } from 'fs';
import { readFileSync, writeFileSync } from 'fs';
import puzzle from '../pawket-chia-lib/services/crypto/puzzle';
import { Instance } from "../pawket-chia-lib/services/util/instance";
import { sha256tree } from 'clvm_tools';
import { sexpAssemble } from '../pawket-chia-lib/services/coin/analyzer';

const suffix = ".clvm.hex";

const nameMappings: { [key: string]: string } = {
settlement_payments: "settlement_payments_v1",
settlement_payments_old: "settlement_payments",
};
import { Glob, GlobOptions } from 'glob'

Instance.init().then(async () => {
const writeTypeFile = async function (dirname: string, typename: string) {
const writeTypeFile = async function (g: Glob<GlobOptions>, typename: string, suffix: string, nameMappings: Record<string, string> = {}) {
const progdata: { [name: string]: string } = {};
const hexdata: { [name: string]: string } = {};
const sha256data: { [name: string]: string } = {};
const names: string[] = [];
const camelName = typename.charAt(0).toLowerCase() + typename.slice(1);

const filenames = readdirSync(dirname);
for (let i = 0; i < filenames.length; i++) {
const filename = filenames[i];
if (!filename.endsWith(suffix)) continue;
const content = readFileSync(dirname + filename, 'utf-8');
const filenames = Array.from(g).sort();
for (const filename of filenames) {
const fn = filename.toString();
const content = readFileSync(fn, 'utf-8');
if (content.indexOf("unknown operator") >= 0) continue;

try {
const hex = content.trim();
const d = await puzzle.disassemblePuzzle(hex);
const originKey = filename.slice(0, filename.length - suffix.length);
const originKey = getFilename(fn.slice(0, fn.length - suffix.length));
const key = nameMappings[originKey] || originKey;
progdata[key] = d;
hexdata[key] = hex;
Expand All @@ -54,7 +47,18 @@ export const ${camelName}sHash: { [name in ${typename}Name]: string } = ${JSON.s
writeFileSync(`../pawket-chia-lib/services/coin/${camelName}s.ts`, content);
};

await writeTypeFile("../../../ref/chia-blockchain/chia/wallet/puzzles/", "ImportMod");
await writeTypeFile("../../../ref/tibet/clvm/", "TibetMod");
await writeTypeFile("clvm/", "OtherMod");
});
await writeTypeFile(new Glob("../../../ref/chia-blockchain/chia/wallet/puzzles/*.clvm.hex", {}), "ImportMod", ".clvm.hex",
{
settlement_payments: "settlement_payments_v1",
settlement_payments_old: "settlement_payments",
});
await writeTypeFile(new Glob("../../../ref/tibet/clvm/*.clvm.hex", {}), "TibetMod", ".clvm.hex");
await writeTypeFile(new Glob("clvm/*.clvm.hex", {}), "OtherMod", ".clvm.hex");
await writeTypeFile(new Glob("../../../ref/internal-custody/cic/clsp/**/*.clsp.hex", {}), "InternalCustodyMod", ".clsp.hex");
await writeTypeFile(new Glob("../../../ref/chia-clawback-primitive/src/clsp/**/*.clsp.hex", {}), "ClawbackPrimitiveMod", ".clsp.hex");
});

function getFilename(fullPath: string) {
// eslint-disable-next-line no-useless-escape
return fullPath.replace(/^.*[\\\/]/, '');
}
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-vue": "^6.2.2",
"express": "^4.18.1",
"glob": "^10.2.2",
"jest": "^28.1.1",
"js-big-decimal": "^1.3.4",
"lerna": "^6.6.1",
Expand Down
19 changes: 19 additions & 0 deletions packages/pawket-chia-lib/services/coin/clawbackPrimitiveMods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export type ClawbackPrimitiveModName = "augmented_condition" | "p2_1_of_n" | "p2_puzzle_hash";

export const clawbackPrimitiveModsProg: { [name in ClawbackPrimitiveModName]: string } = {
"augmented_condition": "(a (q 2 (i (= (a 2 (c 2 (c 23 ()))) 11) (q 4 5 (a 23 47)) (q 8)) 1) (c (q 2 (i (l 5) (q 11 (q . 2) (a 2 (c 2 (c 9 ()))) (a 2 (c 2 (c 13 ())))) (q 11 (q . 1) 5)) 1) 1))",
"p2_1_of_n": "(a (q 2 (i (= 5 (a 6 (c 2 (c (sha256 (q . 1) (a 4 (c 2 (c 23 ())))) (c 11 ()))))) (q 2 23 47) (q 8)) 1) (c (q (a (i (l 5) (q 11 (q . 2) (a 4 (c 2 (c 9 ()))) (a 4 (c 2 (c 13 ())))) (q 11 (q . 1) 5)) 1) 2 (i 27 (q 2 6 (c 2 (c (a (i (logand (q . 1) 19) (q 11 (q . 2) 43 5) (q 11 (q . 2) 5 43)) 1) (c (c (lsh 19 (q . -1)) 59) ())))) (q . 5)) 1) 1))",
"p2_puzzle_hash": "(a (q 2 (i (= 5 (a 2 (c 2 (c 11 ())))) (q 2 11 23) (q 8)) 1) (c (q 2 (i (l 5) (q 11 (q . 2) (a 2 (c 2 (c 9 ()))) (a 2 (c 2 (c 13 ())))) (q 11 (q . 1) 5)) 1) 1))"
};

export const clawbackPrimitiveModsHex: { [name in ClawbackPrimitiveModName]: string } = {
"augmented_condition": "ff02ffff01ff02ffff03ffff09ffff02ff02ffff04ff02ffff04ff17ff80808080ff0b80ffff01ff04ff05ffff02ff17ff2f8080ffff01ff088080ff0180ffff04ffff01ff02ffff03ffff07ff0580ffff01ff0bffff0102ffff02ff02ffff04ff02ffff04ff09ff80808080ffff02ff02ffff04ff02ffff04ff0dff8080808080ffff01ff0bffff0101ff058080ff0180ff018080",
"p2_1_of_n": "ff02ffff01ff02ffff03ffff09ff05ffff02ff06ffff04ff02ffff04ffff0bffff0101ffff02ff04ffff04ff02ffff04ff17ff8080808080ffff04ff0bff808080808080ffff01ff02ff17ff2f80ffff01ff088080ff0180ffff04ffff01ffff02ffff03ffff07ff0580ffff01ff0bffff0102ffff02ff04ffff04ff02ffff04ff09ff80808080ffff02ff04ffff04ff02ffff04ff0dff8080808080ffff01ff0bffff0101ff058080ff0180ff02ffff03ff1bffff01ff02ff06ffff04ff02ffff04ffff02ffff03ffff18ffff0101ff1380ffff01ff0bffff0102ff2bff0580ffff01ff0bffff0102ff05ff2b8080ff0180ffff04ffff04ffff17ff13ffff0181ff80ff3b80ff8080808080ffff010580ff0180ff018080",
"p2_puzzle_hash": "ff02ffff01ff02ffff03ffff09ff05ffff02ff02ffff04ff02ffff04ff0bff8080808080ffff01ff02ff0bff1780ffff01ff088080ff0180ffff04ffff01ff02ffff03ffff07ff0580ffff01ff0bffff0102ffff02ff02ffff04ff02ffff04ff09ff80808080ffff02ff02ffff04ff02ffff04ff0dff8080808080ffff01ff0bffff0101ff058080ff0180ff018080"
};

export const clawbackPrimitiveModsHash: { [name in ClawbackPrimitiveModName]: string } = {
"augmented_condition": "ae7a146f8b13291d8a863eebabea2720a432364a3f8ca376630262d56481a7fd",
"p2_1_of_n": "46b29fd87fbeb6737600c4543931222a6c1ed3db6fa5601a3ca284a9f4efe780",
"p2_puzzle_hash": "13e29a62b42cd2ef72a79e4bacdc59733ca6310d65af83d349360d36ec622363"
};
Loading

0 comments on commit d9d6ce0

Please sign in to comment.