Update config key to registry
This commit is contained in:
parent
5f71d4cc2c
commit
c5bf9793f7
@ -1,4 +1,4 @@
|
|||||||
[upstream]
|
[registry]
|
||||||
rpcEndpoint = "http://localhost:26657"
|
rpcEndpoint = "http://localhost:26657"
|
||||||
chainId = "laconic_9000-1"
|
chainId = "laconic_9000-1"
|
||||||
denom = "photon"
|
denom = "photon"
|
||||||
|
14
src/index.ts
14
src/index.ts
@ -15,7 +15,7 @@ const FAUCET_DATA_FILE = 'faucet_data.sqlite';
|
|||||||
const FAUCET_DATA_TTL = 86400000; // 24 hrs
|
const FAUCET_DATA_TTL = 86400000; // 24 hrs
|
||||||
|
|
||||||
interface Config {
|
interface Config {
|
||||||
upstream: {
|
registry: {
|
||||||
rpcEndpoint: string
|
rpcEndpoint: string
|
||||||
chainId: string
|
chainId: string
|
||||||
denom: string
|
denom: string
|
||||||
@ -50,7 +50,7 @@ async function main (): Promise<void> {
|
|||||||
return res.status(400).json({ error: 'address is required' });
|
return res.status(400).json({ error: 'address is required' });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isValidAddress(accountAddress, config.upstream.prefix)) {
|
if (!isValidAddress(accountAddress, config.registry.prefix)) {
|
||||||
return res.status(400).json({ error: 'invalid address' });
|
return res.status(400).json({ error: 'invalid address' });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,27 +108,27 @@ async function initKVStore (dbDir: string): Promise<Keyv> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function sendTokens (config: Config, recipientAddress: string, amount: string): Promise<string> {
|
async function sendTokens (config: Config, recipientAddress: string, amount: string): Promise<string> {
|
||||||
let faucetKey = config.upstream.faucetKey;
|
let faucetKey = config.registry.faucetKey;
|
||||||
if (faucetKey.startsWith('0x')) {
|
if (faucetKey.startsWith('0x')) {
|
||||||
faucetKey = faucetKey.slice(2);
|
faucetKey = faucetKey.slice(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
const wallet = await DirectSecp256k1Wallet.fromKey(
|
const wallet = await DirectSecp256k1Wallet.fromKey(
|
||||||
Buffer.from(faucetKey, 'hex'),
|
Buffer.from(faucetKey, 'hex'),
|
||||||
config.upstream.prefix
|
config.registry.prefix
|
||||||
);
|
);
|
||||||
const [faucetAccount] = await wallet.getAccounts();
|
const [faucetAccount] = await wallet.getAccounts();
|
||||||
|
|
||||||
const client = await SigningStargateClient.connectWithSigner(
|
const client = await SigningStargateClient.connectWithSigner(
|
||||||
config.upstream.rpcEndpoint,
|
config.registry.rpcEndpoint,
|
||||||
wallet,
|
wallet,
|
||||||
{ gasPrice: GasPrice.fromString(`${config.upstream.gasPrice}${config.upstream.denom}`) }
|
{ gasPrice: GasPrice.fromString(`${config.registry.gasPrice}${config.registry.denom}`) }
|
||||||
);
|
);
|
||||||
|
|
||||||
const result = await client.sendTokens(
|
const result = await client.sendTokens(
|
||||||
faucetAccount.address,
|
faucetAccount.address,
|
||||||
recipientAddress,
|
recipientAddress,
|
||||||
[{ denom: config.upstream.denom, amount: amount }],
|
[{ denom: config.registry.denom, amount: amount }],
|
||||||
'auto',
|
'auto',
|
||||||
'Faucet transfer'
|
'Faucet transfer'
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user