forked from cerc-io/laconic-faucet
Update config key to registry
This commit is contained in:
parent
5f71d4cc2c
commit
c5bf9793f7
@ -1,4 +1,4 @@
|
||||
[upstream]
|
||||
[registry]
|
||||
rpcEndpoint = "http://localhost:26657"
|
||||
chainId = "laconic_9000-1"
|
||||
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
|
||||
|
||||
interface Config {
|
||||
upstream: {
|
||||
registry: {
|
||||
rpcEndpoint: string
|
||||
chainId: string
|
||||
denom: string
|
||||
@ -50,7 +50,7 @@ async function main (): Promise<void> {
|
||||
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' });
|
||||
}
|
||||
|
||||
@ -108,27 +108,27 @@ async function initKVStore (dbDir: string): Promise<Keyv> {
|
||||
}
|
||||
|
||||
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')) {
|
||||
faucetKey = faucetKey.slice(2);
|
||||
}
|
||||
|
||||
const wallet = await DirectSecp256k1Wallet.fromKey(
|
||||
Buffer.from(faucetKey, 'hex'),
|
||||
config.upstream.prefix
|
||||
config.registry.prefix
|
||||
);
|
||||
const [faucetAccount] = await wallet.getAccounts();
|
||||
|
||||
const client = await SigningStargateClient.connectWithSigner(
|
||||
config.upstream.rpcEndpoint,
|
||||
config.registry.rpcEndpoint,
|
||||
wallet,
|
||||
{ gasPrice: GasPrice.fromString(`${config.upstream.gasPrice}${config.upstream.denom}`) }
|
||||
{ gasPrice: GasPrice.fromString(`${config.registry.gasPrice}${config.registry.denom}`) }
|
||||
);
|
||||
|
||||
const result = await client.sendTokens(
|
||||
faucetAccount.address,
|
||||
recipientAddress,
|
||||
[{ denom: config.upstream.denom, amount: amount }],
|
||||
[{ denom: config.registry.denom, amount: amount }],
|
||||
'auto',
|
||||
'Faucet transfer'
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user