Skip to content

Commit

Permalink
Merge branch 'dev' into naynay/faucet
Browse files Browse the repository at this point in the history
  • Loading branch information
rh0delta committed Aug 23, 2024
2 parents f78695a + e33cf72 commit c3c033a
Show file tree
Hide file tree
Showing 31 changed files with 336 additions and 281 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/cla.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
steps:
- name: "CLA Assistant"
if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target'
uses: contributor-assistant/github-action@v2.4.0
uses: entropyxyz/contributor-assistant-github-action@c5f4628ffe1edb97724edb64e0dd4795394d33e5 # exemptRepoOrgMembers
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Required, so that the bot in this repository has `write` permissions to Contents of remote repo.
Expand All @@ -47,5 +47,6 @@ jobs:
path-to-document: 'https://github.com/entropyxyz/.github/blob/main/legal/cla/v1/cla.md'
branch: 'main'
allowlist: dependabot[bot]
exemptRepoOrgMembers: true
remote-organization-name: entropyxyz
remote-repository-name: .github
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,19 @@ Version header format: `[version] Name - year-month-day (entropy-core compatibil
- new: './src/flows/user-program-management/remove.ts' - service file for removing user program pure function

### Changed

- folder name for user programs to match the kebab-case style for folder namespace
- updated SDK version to v0.2.3
- merged user + dev program folders + tests


### Broke

- deploying programs with TUI
- now requires a `*.wasm` file for `bytecode`
- now requires a `*.json` file path for `configurationSchema`
- now requires a `*.json` file path for `auxillaryDataSchema`


## [0.0.3] Blade - 2024-07-17 (entropy-core compatibility: 0.2.0)

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@
"inquirer": "8.0.0",
"lodash.clonedeep": "^4.5.0",
"mkdirp": "^3.0.1",
"typescript": "^4.8.4",
"viem": "^2.7.8",
"winston": "^3.13.0",
"x25519": "^0.1.0"
},
Expand All @@ -64,6 +62,7 @@
"@types/cli-progress": "^3",
"@types/inquirer": "^9.0.2",
"@types/node": "^20.12.12",
"@types/tape": "^5.6.4",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"eslint": "^8.56.0",
Expand Down
5 changes: 2 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { cliGetBalance } from './flows/balance/cli'
import { cliListAccounts } from './flows/manage-accounts/cli'
import { cliEntropyTransfer } from './flows/entropyTransfer/cli'
import { cliSign } from './flows/sign/cli'
import { stringify } from './common/utils'

const program = new Command()

Expand Down Expand Up @@ -112,9 +113,7 @@ program.command('sign')
})

function writeOut (result) {
const prettyResult = typeof result === 'object'
? JSON.stringify(result, null, 2)
: result
const prettyResult = stringify(result)
process.stdout.write(prettyResult)
}

Expand Down
8 changes: 7 additions & 1 deletion src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ export function stripHexPrefix (str: string): string {
return str
}

export function stringify (thing, indent = 2) {
return (typeof thing === 'object')
? JSON.stringify(thing, replacer, indent)
: thing
}

export function replacer (key, value) {
if (value instanceof Uint8Array) {
return Buffer.from(value).toString('base64')
Expand All @@ -14,7 +20,7 @@ export function replacer (key, value) {
}

export function print (...args) {
console.log(...args)
console.log(...args.map(arg => stringify(arg)))
}

// hardcoding for now instead of querying chain
Expand Down
101 changes: 0 additions & 101 deletions src/flows/DeployPrograms/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/flows/entropyFaucet/faucet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Entropy from "@entropyxyz/sdk";
import { blake2AsHex, encodeAddress } from "@polkadot/util-crypto";
import { getBalance } from "../balance/balance";
import { viewPrograms } from "../user-program-management/view";
import { viewPrograms } from "../programs/view";
import FaucetSigner from "./signer";
import { FAUCET_PROGRAM_MOD_KEY, PROGRAM_HASH } from "./constants";

Expand Down
10 changes: 5 additions & 5 deletions src/flows/entropyTransfer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ export async function entropyTransfer ({ accounts, selectedAccount: selectedAcco
)
if (transferStatus.isFinalized) stopProgress()

print(
`\nTransaction successful: Sent ${amount} to ${recipientAddress}`
)
print('\nPress enter to return to main menu')
print('')
print(`Transaction successful: Sent ${amount} to ${recipientAddress}`)
print('')
print('Press enter to return to main menu')
} catch (error) {
stopProgress()
console.error('ERR:::', error);
}
}
}
3 changes: 1 addition & 2 deletions src/flows/index.ts
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'
3 changes: 2 additions & 1 deletion src/flows/manage-accounts/new-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ export async function newAccount ({ accounts }, logger: EntropyLogger) {

const newAccount = await createAccount({ name, seed, path }, logger)

print(`New account:\n{\n\tname: ${newAccount.name}\n\taddress: ${newAccount.address}\n}`)
print('New account:')
print({ name: newAccount.name, address: newAccount.address })

accounts.push(newAccount)
return { accounts, selectedAccount: newAccount.address }
Expand Down
File renamed without changes.
49 changes: 49 additions & 0 deletions src/flows/programs/deploy.ts
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.
30 changes: 30 additions & 0 deletions src/flows/programs/helpers/utils.ts
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')
}
Loading

0 comments on commit c3c033a

Please sign in to comment.