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

Remove register operator proof of ownership #183

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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