|
@@ -4,16 +4,21 @@ function aliceKeyPair (api) {
|
|
|
return api.identities.keyring.addFromUri('//Alice', null, 'sr25519')
|
|
|
}
|
|
|
|
|
|
+function roleKeyPair (api) {
|
|
|
+ return api.identities.keyring.addFromUri('//Colossus', null, 'sr25519')
|
|
|
+}
|
|
|
+
|
|
|
// Setup Alice account on a developement chain that was
|
|
|
// just launched as the storage lead, and a storage provider using the same
|
|
|
// key as the role key
|
|
|
const init = async (api) => {
|
|
|
const alice = aliceKeyPair(api).address
|
|
|
+ const roleAccount = roleKeyPair(api).address
|
|
|
const providerId = 0 // first assignable id
|
|
|
|
|
|
// Check if setup already completed
|
|
|
- if (await api.workers.isRoleAccountOfStorageProvider(providerId, alice)) {
|
|
|
- console.log('Alice already setup as a storage provider')
|
|
|
+ if (await api.workers.isRoleAccountOfStorageProvider(providerId, roleAccount)) {
|
|
|
+ console.log('//Colossus already setup as a storage provider')
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -24,6 +29,9 @@ const init = async (api) => {
|
|
|
throw new Error('Setup requires Alice to be sudo. Are you sure you are running a devchain?')
|
|
|
}
|
|
|
|
|
|
+ // Give role account some tokens to work with
|
|
|
+ api.balances.transfer(alice, roleAccount, 100000)
|
|
|
+
|
|
|
// register alice as a member
|
|
|
console.log(`Registering Alice as a member`)
|
|
|
const aliceMemberId = await api.identities.registerMember(alice, {
|
|
@@ -45,7 +53,7 @@ const init = async (api) => {
|
|
|
// first assignable id == 0
|
|
|
// so we don't await each tx to finalize to get the ids. this allows us to
|
|
|
// batch all the transactions into a single block.
|
|
|
- console.log('Making Alice a storage provider')
|
|
|
+ console.log('Making //Colossus account a storage provider')
|
|
|
const openTx = api.api.tx.storageWorkingGroup.addWorkerOpening('CurrentBlock', {
|
|
|
application_rationing_policy: {
|
|
|
'max_active_applicants': 1
|
|
@@ -56,7 +64,7 @@ const init = async (api) => {
|
|
|
api.signAndSend(alice, openTx)
|
|
|
const openingId = 0 // first assignable opening id
|
|
|
const applyTx = api.api.tx.storageWorkingGroup.applyOnWorkerOpening(
|
|
|
- aliceMemberId, openingId, alice, null, null, 'alice'
|
|
|
+ aliceMemberId, openingId, roleAccount, null, null, 'colossus'
|
|
|
)
|
|
|
api.signAndSend(alice, applyTx)
|
|
|
const applicantId = 0 // first assignable applicant id
|
|
@@ -65,31 +73,32 @@ const init = async (api) => {
|
|
|
api.signAndSend(alice, reviewTx)
|
|
|
|
|
|
const fillTx = api.api.tx.storageWorkingGroup.fillWorkerOpening(openingId, [applicantId], null)
|
|
|
-
|
|
|
await api.signAndSend(alice, fillTx)
|
|
|
|
|
|
- // const worker = await api.workers.storageWorkerByProviderId(providerId)
|
|
|
- if (await api.workers.isRoleAccountOfStorageProvider(providerId, alice)) {
|
|
|
- console.log('Setup Alice successfully as storage provider')
|
|
|
+ // wait for previous transactions to finalize so we can read correct state
|
|
|
+ if (await api.workers.isRoleAccountOfStorageProvider(providerId, roleAccount)) {
|
|
|
+ console.log('Setup //Colossus successfully as storage provider')
|
|
|
} else { throw new Error('Setup Failed') }
|
|
|
|
|
|
// set localhost colossus as discovery provider on default port
|
|
|
// assuming pioneer dev server is running on port 3000 we should run
|
|
|
// the storage dev server on port 3001
|
|
|
+ console.log('Setting Local development node as bootstrap endpoint')
|
|
|
await api.discovery.setBootstrapEndpoints(alice, ['http://localhost:3001/'])
|
|
|
}
|
|
|
|
|
|
const check = async (api) => {
|
|
|
const providerId = 0 // the first provider id which would have been assigned in dev-init
|
|
|
- const roleAccountId = aliceKeyPair(api).address
|
|
|
+ const roleAccountId = roleKeyPair(api).address
|
|
|
+ const alice = aliceKeyPair(api).address
|
|
|
|
|
|
if (await api.workers.isRoleAccountOfStorageProvider(providerId, roleAccountId)) {
|
|
|
- console.log('Alice is correctly setup as a storage provider')
|
|
|
- } else { throw new Error('Alice is not setup as a storage provider') }
|
|
|
+ console.log('//Colossus is correctly setup as a storage provider with providerId = 0')
|
|
|
+ } else { throw new Error('//Colossus is not setup as a storage provider') }
|
|
|
|
|
|
const currentLead = await api.api.query.storageWorkingGroup.currentLead()
|
|
|
|
|
|
- if (currentLead.isSome && currentLead.unwrap().role_account_id.eq(roleAccountId)) {
|
|
|
+ if (currentLead.isSome && currentLead.unwrap().role_account_id.eq(alice)) {
|
|
|
console.log('Alice is correctly setup as the storage lead')
|
|
|
} else { throw new Error('Alice is not the storage lead') }
|
|
|
}
|
|
@@ -97,5 +106,6 @@ const check = async (api) => {
|
|
|
module.exports = {
|
|
|
init,
|
|
|
check,
|
|
|
- aliceKeyPair
|
|
|
+ aliceKeyPair,
|
|
|
+ roleKeyPair
|
|
|
}
|