-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into naynay/faucet
- Loading branch information
Showing
31 changed files
with
336 additions
and
281 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
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 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
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 |
---|---|---|
@@ -1,8 +1,7 @@ | ||
export { entropyFaucet } from './entropyFaucet' | ||
export { checkBalance } from './balance' | ||
export { entropyRegister } from './register' | ||
export { userPrograms } from './user-program-management' | ||
export { devPrograms } from './DeployPrograms' | ||
export { userPrograms, devPrograms } from './programs' | ||
export { sign } from './sign' | ||
export { entropyTransfer } from './entropyTransfer' | ||
export { manageAccounts } from './manage-accounts' |
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
File renamed without changes.
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,49 @@ | ||
import Entropy from "@entropyxyz/sdk"; | ||
import fs from "node:fs/promises" | ||
import { isAbsolute, join } from "node:path" | ||
import { u8aToHex } from "@polkadot/util" | ||
|
||
import { DeployProgramParams } from "./types" | ||
|
||
export async function deployProgram (entropy: Entropy, params: DeployProgramParams) { | ||
const bytecode = await loadFile(params.bytecodePath) | ||
const configurationSchema = await loadFile(params.configurationSchemaPath, 'json') | ||
const auxillaryDataSchema = await loadFile(params.auxillaryDataSchemaPath, 'json') | ||
// QUESTION: where / how are schema validated? | ||
|
||
return entropy.programs.dev.deploy( | ||
bytecode, | ||
jsonToHex(configurationSchema), | ||
jsonToHex(auxillaryDataSchema) | ||
) | ||
} | ||
|
||
function loadFile (path?: string, encoding?: string) { | ||
if (path === undefined) return | ||
|
||
const absolutePath = isAbsolute(path) | ||
? path | ||
: join(process.cwd(), path) | ||
|
||
switch (encoding) { | ||
case undefined: | ||
return fs.readFile(absolutePath) | ||
|
||
case 'json': | ||
return fs.readFile(absolutePath, 'utf-8') | ||
.then(string => JSON.parse(string)) | ||
|
||
default: | ||
throw Error('unknown encoding: ' + encoding) | ||
// return fs.readFile(absolutePath, encoding) | ||
} | ||
} | ||
|
||
function jsonToHex (obj?: object) { | ||
if (obj === undefined) return | ||
|
||
const encoder = new TextEncoder() | ||
const byteArray = encoder.encode(JSON.stringify(obj)) | ||
|
||
return u8aToHex(new Uint8Array(byteArray)) | ||
} |
File renamed without changes.
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,30 @@ | ||
import { print } from "src/common/utils" | ||
|
||
export function displayPrograms (programs): void { | ||
programs.forEach((program, index) => { | ||
print(`${index + 1}.`) | ||
print({ | ||
pointer: program.program_pointer, | ||
config: parseProgramConfig(program.program_config) | ||
}) | ||
print('') | ||
}) | ||
} | ||
|
||
function parseProgramConfig (rawConfig: unknown) { | ||
if (typeof rawConfig !== 'string') return rawConfig | ||
if (!rawConfig.startsWith('0x')) return rawConfig | ||
|
||
const hex = rawConfig.slice(2) | ||
const utf8 = Buffer.from(hex, 'hex').toString() | ||
const output = JSON.parse(utf8) | ||
Object.keys(output).forEach(key => { | ||
output[key] = output[key].map(base64toHex) | ||
}) | ||
|
||
return output | ||
} | ||
|
||
function base64toHex (base64: string): string { | ||
return Buffer.from(base64, 'base64').toString('hex') | ||
} |
Oops, something went wrong.