Add functionality to create a validator #28
@ -4,6 +4,7 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@cerc-io/registry-sdk": "^0.2.5",
|
"@cerc-io/registry-sdk": "^0.2.5",
|
||||||
|
"@cosmjs/crypto": "^0.32.4",
|
||||||
"@cosmjs/encoding": "^0.32.4",
|
"@cosmjs/encoding": "^0.32.4",
|
||||||
"@cosmjs/proto-signing": "^0.32.4",
|
"@cosmjs/proto-signing": "^0.32.4",
|
||||||
"@cosmjs/stargate": "^0.32.4",
|
"@cosmjs/stargate": "^0.32.4",
|
||||||
|
@ -4,19 +4,22 @@ import { enqueueSnackbar } from 'notistack';
|
|||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
import { MsgCreateValidatorEncodeObject } from '@cosmjs/stargate';
|
import { MsgCreateValidatorEncodeObject } from '@cosmjs/stargate';
|
||||||
import { fromBech32, toBech32 } from '@cosmjs/encoding';
|
import {MsgCreateValidator} from '@cerc-io/registry-sdk';
|
||||||
|
import { fromBase64, fromBech32, toBech32 } from '@cosmjs/encoding';
|
||||||
import { LoadingButton } from '@mui/lab';
|
import { LoadingButton } from '@mui/lab';
|
||||||
import { encodePubkey } from '@cosmjs/proto-signing';
|
import { encodePubkey } from '@cosmjs/proto-signing';
|
||||||
import { Registry } from '@cerc-io/registry-sdk';
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
import { useWalletConnectContext } from '../context/WalletConnectContext'
|
import { useWalletConnectContext } from '../context/WalletConnectContext'
|
||||||
import { Participant } from '../types';
|
import { Participant } from '../types';
|
||||||
|
import { PubKey as CosmosCryptoEd25519Pubkey } from 'cosmjs-types/cosmos/crypto/ed25519/keys';
|
||||||
|
import { Any } from 'cosmjs-types/google/protobuf/any';
|
||||||
|
|
||||||
const CreateValidator = () => {
|
const CreateValidator = () => {
|
||||||
const {session, signClient} = useWalletConnectContext();
|
const {session, signClient} = useWalletConnectContext();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const [cosmosAddress, setCosmosAddress] = useState('');
|
const [cosmosAddress, setCosmosAddress] = useState('laconic1z4l4556v8jnk7k456ujme720nk8mzjwhka7qvw');
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [pubkey, setPubkey] = useState('d5aOEYaCIHaDn6kG0tAg699D7sLgAgkJI5reTMl0o5U=');
|
const [pubkey, setPubkey] = useState('d5aOEYaCIHaDn6kG0tAg699D7sLgAgkJI5reTMl0o5U=');
|
||||||
const [participant, setParticipant] = useState<Participant | null>(null);
|
const [participant, setParticipant] = useState<Participant | null>(null);
|
||||||
@ -25,42 +28,49 @@ const CreateValidator = () => {
|
|||||||
navigate("/connect-wallet")
|
navigate("/connect-wallet")
|
||||||
}
|
}
|
||||||
|
|
||||||
const changePrefix = (address: string, newPrefix: string): string => {
|
const pubkeyProto = CosmosCryptoEd25519Pubkey.fromPartial({
|
||||||
return toBech32(newPrefix, fromBech32(address).data);
|
key: fromBase64(pubkey)
|
||||||
}
|
});
|
||||||
|
|
||||||
const createValidatorMessage: MsgCreateValidatorEncodeObject =
|
const updatedPubKey = Any.fromPartial({
|
||||||
|
typeUrl: '/cosmos.crypto.ed25519.PubKey',
|
||||||
|
value: Uint8Array.from(CosmosCryptoEd25519Pubkey.encode(pubkeyProto).finish())
|
||||||
|
});
|
||||||
|
|
||||||
|
const msgCreateValidator: MsgCreateValidator =
|
||||||
useMemo(() => {
|
useMemo(() => {
|
||||||
return {
|
return {
|
||||||
typeUrl: "/cosmos.staking.v1beta1.MsgCreateValidator",
|
description: {
|
||||||
|
moniker: "dockerNode",
|
||||||
|
identity: "",
|
||||||
|
website: "",
|
||||||
|
securityContact: "",
|
||||||
|
details: "",
|
||||||
|
},
|
||||||
|
commission: {
|
||||||
|
maxChangeRate: "10000000000000000", // 0.01
|
||||||
|
maxRate: "200000000000000000", // 0.2
|
||||||
|
rate: "100000000000000000", // 0.1
|
||||||
|
},
|
||||||
|
minSelfDelegation: "1",
|
||||||
|
delegatorAddress: cosmosAddress,
|
||||||
|
validatorAddress: toBech32('laconicvaloper', fromBech32(cosmosAddress).data),
|
||||||
|
// pubkey: encodePubkey({
|
||||||
|
// type: "tendermint/PubKeyEd25519",
|
||||||
|
// value: pubkey,
|
||||||
|
// }),
|
||||||
|
pubkey: updatedPubKey,
|
||||||
value: {
|
value: {
|
||||||
description: {
|
amount: process.env.REACT_APP_STAKING_AMOUNT!,
|
||||||
moniker: "dockerNode",
|
denom: process.env.REACT_APP_LACONICD_DENOM!,
|
||||||
identity: "",
|
|
||||||
website: "",
|
|
||||||
securityContact: "",
|
|
||||||
details: "",
|
|
||||||
},
|
|
||||||
commission: {
|
|
||||||
maxChangeRate: "10000000000000000", // 0.01
|
|
||||||
maxRate: "200000000000000000", // 0.2
|
|
||||||
rate: "100000000000000000", // 0.1
|
|
||||||
},
|
|
||||||
minSelfDelegation: "1",
|
|
||||||
delegatorAddress: cosmosAddress,
|
|
||||||
// validatorAddress: changePrefix(cosmosAddress, "laconicvaloper"),
|
|
||||||
validatorAddress: "laconicvaloper1ru0s5tu0cj3xmt8zdfrmz74p0c6lj73nqfpt2q",
|
|
||||||
pubkey: encodePubkey({
|
|
||||||
type: "tendermint/PubKeyEd25519",
|
|
||||||
value: pubkey,
|
|
||||||
}),
|
|
||||||
value: {
|
|
||||||
amount: process.env.REACT_APP_STAKING_AMOUNT!,
|
|
||||||
denom: process.env.REACT_APP_LACONICD_DENOM!,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}, [cosmosAddress, pubkey]);
|
}, [cosmosAddress, updatedPubKey]);
|
||||||
|
|
||||||
|
const msgCreateValidatorEncodeObject: MsgCreateValidatorEncodeObject = {
|
||||||
|
typeUrl: '/cosmos.staking.v1beta1.MsgCreateValidator',
|
||||||
|
value: msgCreateValidator
|
||||||
|
};
|
||||||
|
|
||||||
const sendTransaction = async (
|
const sendTransaction = async (
|
||||||
transactionMessage: MsgCreateValidatorEncodeObject
|
transactionMessage: MsgCreateValidatorEncodeObject
|
||||||
@ -193,14 +203,15 @@ const CreateValidator = () => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<pre style={{ whiteSpace: "pre-wrap", margin: 0 }}>
|
<pre style={{ whiteSpace: "pre-wrap", margin: 0 }}>
|
||||||
{JSON.stringify(createValidatorMessage, null, 2)}
|
{JSON.stringify(msgCreateValidator, null, 2)}
|
||||||
</pre>
|
</pre>
|
||||||
</Box>
|
</Box>
|
||||||
<Box marginTop={1}>
|
<Box marginTop={1}>
|
||||||
<LoadingButton
|
<LoadingButton
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
await sendTransaction(createValidatorMessage);
|
console.log(msgCreateValidatorEncodeObject);
|
||||||
|
await sendTransaction(msgCreateValidatorEncodeObject);
|
||||||
}}
|
}}
|
||||||
loading={isLoading}
|
loading={isLoading}
|
||||||
>
|
>
|
||||||
@ -215,4 +226,4 @@ const CreateValidator = () => {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CreateValidator
|
export default CreateValidator
|
||||||
|
Loading…
Reference in New Issue
Block a user