Skip to content

Commit

Permalink
Merge pull request #183 from autonomys/feat/remove-register-operator-…
Browse files Browse the repository at this point in the history
…proof-of-ownership

Remove register operator proof of ownership
  • Loading branch information
marc-aurele-besner authored Nov 27, 2024
2 parents 4beecdc + d13a21f commit 8ca0dec
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 28 deletions.
3 changes: 1 addition & 2 deletions examples/next/src/components/actions/register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ export const RegisterOperator = () => {
await handleTx(
await registerOperator({
api: selectedWallet.api,
senderAddress: selectedWallet.accounts[0].address,
Operator: operatorAccounts[0],
domainId,
amountToStake,
minimumNominatorStake,
nominationTax,
publicKey: operatorAccounts[0].publicKey,
}),
setErrorForm,
)
Expand Down
38 changes: 14 additions & 24 deletions packages/auto-consensus/src/staking.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// file: src/staking.ts

import type { Api } from '@autonomys/auto-utils'
import { createAccountIdType, signingKey } from '@autonomys/auto-utils'
import { signingKey as signingKeyFn } from '@autonomys/auto-utils'
import type {
NominateOperatorParams,
RegisterOperatorParams,
Expand Down Expand Up @@ -70,29 +70,19 @@ export const withdrawals = async (

export const registerOperator = (params: RegisterOperatorParams) => {
try {
const {
api,
senderAddress,
Operator,
domainId,
amountToStake,
minimumNominatorStake,
nominationTax,
} = params

const message = createAccountIdType(api, senderAddress)
const signature = Operator.sign(message)

return api.tx.domains.registerOperator(
parseString(domainId),
parseString(amountToStake),
{
signingKey: signingKey(Operator.publicKey),
minimumNominatorStake: parseString(minimumNominatorStake),
nominationTax: parseString(nominationTax),
},
signature,
)
const { api, domainId, amountToStake, minimumNominatorStake, nominationTax, publicKey } = params
let signingKey = params.signingKey

if (!signingKey && !publicKey) throw new Error('Signing key or public key not provided')
else if (!signingKey && publicKey) signingKey = signingKeyFn(publicKey)

if (!signingKey) throw new Error('Signing key not provided')

return api.tx.domains.registerOperator(parseString(domainId), parseString(amountToStake), {
signingKey,
minimumNominatorStake: parseString(minimumNominatorStake),
nominationTax: parseString(nominationTax),
})
} catch (error) {
console.error('error', error)
throw new Error('Error creating register operator tx.' + error)
Expand Down
4 changes: 2 additions & 2 deletions packages/auto-consensus/src/types/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ export type StringNumberOrBigInt = string | number | bigint

export type RegisterOperatorParams = {
api: ApiPromise
senderAddress: string
Operator: KeyringPair
domainId: StringNumberOrBigInt
amountToStake: StringNumberOrBigInt
minimumNominatorStake: StringNumberOrBigInt
nominationTax: StringNumberOrBigInt
signingKey?: string
publicKey?: Uint8Array
}

export type StakingParams = {
Expand Down

0 comments on commit 8ca0dec

Please sign in to comment.