Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tx queue #1124

Merged
merged 44 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
f98279c
Batch commit behind admin auth
HughParry Jan 17, 2024
55b12a5
transaction queue initial implementation
forgetso Jan 18, 2024
5a115e4
Change test account structure
forgetso Jan 19, 2024
1e40a9b
Update encode decode so that the output is nicely formatted
forgetso Jan 22, 2024
5564158
Simply print errors
forgetso Jan 22, 2024
248f592
switch JSON and table order
forgetso Jan 22, 2024
0f5a04d
Add stringToHex
forgetso Jan 22, 2024
95b09bb
Add stringToU8a
forgetso Jan 22, 2024
0e278c4
Changes to test account types
forgetso Jan 23, 2024
c960789
Merge branch 'main' into tx-queue
forgetso Jan 23, 2024
284eb21
Make admin API optional
forgetso Jan 23, 2024
e7dd0ff
Fix reloading API
forgetso Jan 23, 2024
2f86cc1
Script for fixing unregistered and unfunded dapps in contract
forgetso Mar 25, 2024
e608ecd
Remove commented
forgetso Mar 25, 2024
41bfa74
remove broken script runner
forgetso Mar 25, 2024
a2170fb
Update description
forgetso Mar 25, 2024
35b8de6
remove ts-node
forgetso Mar 25, 2024
fd30d86
remove ts-node
forgetso Mar 25, 2024
5fc5acc
remove manual email and name checks
forgetso Mar 25, 2024
1e3e1c3
remove unused contractTx function
forgetso Mar 25, 2024
cb0182e
build:typechain
forgetso Mar 25, 2024
3fc3578
license
forgetso Mar 25, 2024
f649784
Merge branch 'main' into tx-queue
forgetso Mar 27, 2024
4f733ec
Merge branch 'main' into tx-queue
forgetso Mar 27, 2024
49d9bfb
Merge branch 'main' into tx-queue
forgetso Apr 13, 2024
63f29f4
fix broken merge
forgetso Apr 13, 2024
60ecd71
Merge branch 'main' into tx-queue
forgetso Apr 15, 2024
c7d2ba9
Make sure correct pairs are used when sending txs and correct account…
forgetso Apr 15, 2024
a2f6b21
build:typechain
forgetso Apr 15, 2024
e0849f1
Move tx queue into its own package
forgetso Apr 16, 2024
e6d3ecb
lint:fix
forgetso Apr 16, 2024
04a1b11
build:typechain
forgetso Apr 16, 2024
f9f65fb
remove trailing commans
forgetso Apr 16, 2024
8d63e42
remove commented
forgetso Apr 16, 2024
9b595c4
Remove return from immediately returning functions
forgetso Apr 16, 2024
de04658
Fail immediately if atlasURI not supplied
forgetso Apr 16, 2024
21a8f7e
Supply function name
forgetso Apr 16, 2024
72a1bf1
Add error when contract error is unretrieveable
forgetso Apr 16, 2024
89f7d3e
Remove let
forgetso Apr 16, 2024
94ddd66
Use prosopo error handler
forgetso Apr 16, 2024
6244136
Remove type
forgetso Apr 16, 2024
0eab09b
remove rogue logging
forgetso Apr 16, 2024
f6d578a
Merge branch 'main' into tx-queue
forgetso Apr 16, 2024
5d3791c
pass Error into prosopo error instance
forgetso Apr 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/captcha/src/captcha.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source": {
"hash": "0xf4168d7539ede275d65767189c733756a504f6657609e9e0ba2e6ac654323814",
"hash": "0x082a3b92ea430de7ed186bc7d90d69df7dd9e7916cae5b6e393541ef3d991c1b",
"language": "ink! 4.3.0",
"compiler": "rustc 1.69.0",
"build_info": {
Expand Down
4 changes: 2 additions & 2 deletions contracts/captcha/src/contract-info/captcha.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/common/src/common.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source": {
"hash": "0xe4cac088ed09b43809b11b51eea2d7543fdc784b371332886e7922b13d2ab3b4",
"hash": "0x13cc7cae4f185558a84388a1440b6cacec75efdaaa5716c560d5df3f5bbddf4a",
"language": "ink! 4.3.0",
"compiler": "rustc 1.69.0",
"build_info": {
Expand Down
4 changes: 2 additions & 2 deletions contracts/common/src/contract-info/common.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions contracts/proxy/src/contract-info/proxy.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/proxy/src/proxy.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source": {
"hash": "0x914ffc648b57fb989d0ee412f7f66775a735a4a57d5beb132967dc715e660224",
"hash": "0x5d40e1e33a0857b98db56378c7c58e06f0c6fdb36a547f0909acffc756d2902b",
"language": "ink! 4.3.0",
"compiler": "rustc 1.69.0",
"build_info": {
Expand Down
158 changes: 41 additions & 117 deletions dev/config/src/projectInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,158 +20,82 @@ export const getContractNames = () => {
})
}

export const getRootDir = () => {
return new URL('../../..', import.meta.url).pathname.slice(0, -1)
}
export const getRootDir = () => new URL('../../..', import.meta.url).pathname.slice(0, -1)

export const getCacheDir = () => {
return `${getRootDir()}/.cache`
}
export const getCacheDir = () => `${getRootDir()}/.cache`

export const getTestResultsDir = () => {
return `${getCacheDir()}/test-results`
}
export const getTestResultsDir = () => `${getCacheDir()}/test-results`

export const getDevDir = () => {
return `${getRootDir()}/dev`
}
export const getDevDir = () => `${getRootDir()}/dev`

export const getDemosDir = () => {
return `${getRootDir()}/demos`
}
export const getDemosDir = () => `${getRootDir()}/demos`

export const getContractDir = () => {
return `${getRootDir()}/packages/contract`
}
export const getContractDir = () => `${getRootDir()}/packages/contract`

export const getProtocolDir = () => {
return `${getRootDir()}/protocol`
}
export const getProtocolDir = () => `${getRootDir()}/protocol`

export const getPackagesDir = () => {
return `${getRootDir()}/packages`
}
export const getPackagesDir = () => `${getRootDir()}/packages`

export const getNodeModulesDir = () => {
return `${getRootDir()}/node_modules`
}
export const getNodeModulesDir = () => `${getRootDir()}/node_modules`

export const getConfigPkgDir = () => {
return `${getDevDir()}/config`
}
export const getConfigPkgDir = () => `${getDevDir()}/config`

export const getScriptsPkgDir = () => {
return `${getDevDir()}/scripts`
}
export const getScriptsPkgDir = () => `${getDevDir()}/scripts`

export const getProtocolCliDir = () => {
return `${getProtocolDir()}/dist/cli`
}
export const getProtocolCliDir = () => `${getProtocolDir()}/dist/cli`

export const getProtocolDistDir = () => {
return `${getProtocolDir()}/target/ink`
}
export const getProtocolDistDir = () => `${getProtocolDir()}/target/ink`

export const getClientExampleDir = () => {
return `${getDemosDir()}/client-example`
}
export const getClientExampleDir = () => `${getDemosDir()}/client-example`

export const getClientExampleServerDir = () => {
return `${getDemosDir()}/client-example-server`
}
export const getClientExampleServerDir = () => `${getDemosDir()}/client-example-server`

export const getClientBundleExampleDir = () => {
return `${getDemosDir()}/client-bundle-example`
}
export const getClientBundleExampleDir = () => `${getDemosDir()}/client-bundle-example`

export const getDappExampleDir = () => {
return `${getDemosDir()}/dapp-example`
}
export const getDappExampleDir = () => `${getDemosDir()}/dapp-example`

export const getCommonPkgDir = () => {
return `${getPackagesDir()}/common`
}
export const getCommonPkgDir = () => `${getPackagesDir()}/common`

export const getAccountPkgDir = () => {
return `${getPackagesDir()}/account`
}
export const getAccountPkgDir = () => `${getPackagesDir()}/account`

export const getApiPkgDir = () => {
return `${getPackagesDir()}/api`
}
export const getApiPkgDir = () => `${getPackagesDir()}/api`

export const getCliPkgDir = () => {
return `${getPackagesDir()}/cli`
}
export const getCliPkgDir = () => `${getPackagesDir()}/cli`

export const getUtilPkgDir = () => {
return `${getPackagesDir()}/util`
}
export const getUtilPkgDir = () => `${getPackagesDir()}/util`

export const getDatabasePkgDir = () => {
return `${getPackagesDir()}/database`
}
export const getDatabasePkgDir = () => `${getPackagesDir()}/database`

export const getDatasetsPkgDir = () => {
return `${getPackagesDir()}/datasets`
}
export const getDatasetsPkgDir = () => `${getPackagesDir()}/datasets`

export const getDatasetsFsPkgDir = () => {
return `${getPackagesDir()}/datasets-fs`
}
export const getDatasetsFsPkgDir = () => `${getPackagesDir()}/datasets-fs`

export const getEnvPkgDir = () => {
return `${getPackagesDir()}/env`
}
export const getEnvPkgDir = () => `${getPackagesDir()}/env`

export const getFileServerPkgDir = () => {
return `${getPackagesDir()}/file-server`
}
export const getFileServerPkgDir = () => `${getPackagesDir()}/file-server`

export const getProcaptchaPkgDir = () => {
return `${getPackagesDir()}/procaptcha`
}
export const getProcaptchaPkgDir = () => `${getPackagesDir()}/procaptcha`

export const getProcaptchaReactPkgDir = () => {
return `${getPackagesDir()}/procaptcha-react`
}
export const getProcaptchaReactPkgDir = () => `${getPackagesDir()}/procaptcha-react`

export const getProcaptchaBundlePkgDir = () => {
return `${getPackagesDir()}/procaptcha-bundle`
}
export const getProcaptchaBundlePkgDir = () => `${getPackagesDir()}/procaptcha-bundle`

export const getProcaptchaPoWPkgDir = () => {
return `${getPackagesDir()}/procaptcha-pow`
}
export const getProcaptchaPoWPkgDir = () => `${getPackagesDir()}/procaptcha-pow`

export const getProviderPkgDir = () => {
return `${getPackagesDir()}/provider`
}
export const getProviderPkgDir = () => `${getPackagesDir()}/provider`

export const getServerPkgDir = () => {
return `${getPackagesDir()}/server`
}
export const getServerPkgDir = () => `${getPackagesDir()}/server`

export const getTypesDatabasePkgDir = () => {
return `${getPackagesDir()}/types-database`
}
export const getTypesDatabasePkgDir = () => `${getPackagesDir()}/types-database`

export const getTypesEnvPkgDir = () => {
return `${getPackagesDir()}/types-env`
}
export const getTypesEnvPkgDir = () => `${getPackagesDir()}/types-env`

export const getTypesPkgDir = () => {
return `${getPackagesDir()}/types`
}
export const getTypesPkgDir = () => `${getPackagesDir()}/types`

export const getWebComponentsPkgDir = () => {
return `${getPackagesDir()}/web-components`
}
export const getTxPkgDir = () => `${getPackagesDir()}/tx`

export const getContractsDir = () => {
return `${getRootDir()}/contracts`
}
export const getWebComponentsPkgDir = () => `${getPackagesDir()}/web-components`

export const getProtocolContractsDir = () => {
return `${getProtocolDir()}/contracts`
}
export const getContractsDir = () => `${getRootDir()}/contracts`

export const getProtocolContractsDir = () => `${getProtocolDir()}/contracts`
1 change: 1 addition & 0 deletions dev/config/src/vite/vite.test.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default function () {
},
test: {
//root: getRootDir(),
reporters: ['basic'],
include: ['src/**/*.{test,spec}.?(c|m)[jt]s?(x)'],
watch: false,
watchExclude: ['**/node_modules/**', '**/dist/**'],
Expand Down
121 changes: 121 additions & 0 deletions dev/scripts/src/contract/fundDapps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Copyright 2021-2024 Prosopo (UK) Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { Abi } from '@polkadot/api-contract'
import { AbiJSON, Wasm } from '../util/index.js'
import { ContractAbi } from '@prosopo/captcha-contract/contract-info'
import { ContractFile } from '@prosopo/captcha-contract/contract-info'
import { LogLevel, getLogger } from '@prosopo/common'
import { ProviderEnvironment } from '@prosopo/env'
import { TransactionQueue } from '@prosopo/tx'
import { defaultConfig } from '@prosopo/cli'
import { getPairAsync, oneUnit } from '@prosopo/contract'
import { hexToU8a } from '@polkadot/util'
import { loadEnv } from '@prosopo/cli'
import { setupDapp } from '../setup/index.js'
import mongoose, { Model } from 'mongoose'
import path from 'path'

const log = getLogger(LogLevel.enum.info, 'dev.deploy')

interface Emails {
email: string
name: string
url: string
account: string
mnemonic: string
createdAt: number
marketingPreferences: boolean
}

const EmailModelSchema = new mongoose.Schema<Emails>(
{
email: String,
name: String,
url: String,
account: String,
mnemonic: String,
createdAt: Number,
marketingPreferences: Boolean,
},
{ collection: 'emails' }
)

let EmailsModel: typeof Model<Emails>
try {
EmailsModel = mongoose.model('emails')
} catch (error) {
EmailsModel = mongoose.model('emails', EmailModelSchema)
}

export async function run(wasmPath: string | undefined, abiPath: string | undefined, atlasUri: string | undefined) {
if (!atlasUri) {
throw new Error('Atlas URI not found in env')
}
// if wasmPath not provided then default to the captcha contract's wasm
let wasm: Uint8Array
if (wasmPath === undefined) {
log.info('Using wasm from captcha contract')
const jsonContent = JSON.parse(ContractFile)
const hex = jsonContent['source']['wasm']
wasm = hexToU8a(hex)
} else {
log.info('WASM Path', wasmPath)
wasm = await Wasm(path.resolve(wasmPath))
}
// if abiPath not provided then default to the captcha contract's abi
let abi: Abi
if (abiPath === undefined) {
log.info('Using abi from captcha contract')
abi = new Abi(ContractAbi)
} else {
log.info('ABI Path', abiPath)
abi = await AbiJSON(path.resolve(abiPath))
}

await mongoose.connect(atlasUri, { dbName: 'prosopo' })

const dapps = await EmailsModel.find({}).exec()
log.info(dapps)

const config = defaultConfig()
const network = config.networks[config.defaultNetwork]
const secret = config.account.secret
const pair = await getPairAsync(network, secret)
const env = new ProviderEnvironment(config, pair)
await env.isReady()
forgetso marked this conversation as resolved.
Show resolved Hide resolved
const queue = new TransactionQueue(env.getApi(), pair, config.logLevel)
if (!config.account.address) {
throw new Error('Account address not found in config')
}
if (!secret) {
throw new Error('Account secret not found in config')
}
const fundAmount = oneUnit(env.getApi())
await Promise.all(
dapps
.filter((dappRecord) => dappRecord.account)
.map((dappRecord) => setupDapp(env, { pair, secret, fundAmount }, dappRecord.account, queue))
)
}
log.info('Loading env from', path.resolve('.'))
loadEnv(path.resolve('.'))
run(process.env.PROSOPO_CAPTCHA_WASM_PATH, process.env.PROSOPO_CAPTCHA_ABI_PATH, process.env._DEV_ONLY_ATLAS_URI)
.then((result) => {
log.info(result)
process.exit(0)
})
.catch((e) => {
console.error(e)
process.exit(1)
})
Loading
Loading