Skip to content

Commit

Permalink
feat(drip): multi-chain config
Browse files Browse the repository at this point in the history
  • Loading branch information
cor committed Sep 5, 2024
1 parent feeb26d commit e80d02a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
22 changes: 21 additions & 1 deletion drip/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
"id": "union-devnet-1",
"bech32_prefix": "union",
"memo": "drip drop",
"memo": "drip drop greetings from union faucet",
"ws_url": "ws://localhost:26657/websocket",
"grpc_url": "http://localhost:9090",
"gas_config": {
Expand All @@ -23,6 +23,26 @@
"amount": 13370
}
]
},
{
"id": "stargaze-devnet-1",
"bech32_prefix": "stars",
"memo": "drip drop greetings from union faucet on stargaze",
"ws_url": "ws://localhost:26757/websocket",
"grpc_url": "http://localhost:9190",
"gas_config": {
"gas_price": "1.0",
"gas_denom": "ustars",
"gas_multiplier": "1.1",
"max_gas": 40000000
},
"signer": "0xaa820fa947beb242032a41b6dc9a8b9c37d8f5fbcda0966b1ec80335b10a7d6f",
"coins": [
{
"denom": "ustars",
"amount": 13370
}
]
}
]
}
9 changes: 9 additions & 0 deletions drip/example-request-stars.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"query": "mutation UnoFaucetMutation($chain_id: String!, $denom: String!, $address: String!, $captchaToken: String!) { send(chainId: $chain_id, denom: $denom, address: $address, captchaToken: $captchaToken) }",
"variables": {
"chain_id": "stargaze-devnet-1",
"denom": "ustars",
"address": "stars1yt66vjvy3dp3m2e49tffvxe7vwf6qrukkj8ax6",
"captchaToken": "helloworld"
}
}
16 changes: 14 additions & 2 deletions drip/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,23 @@ async fn main() {
)
.expect("???");

let mut rows = stmt.query((chain.id, batch_size as i64)).expect("can't query rows");
let mut rows = stmt.query((&chain.id, batch_size as i64)).expect("can't query rows");

let mut requests = vec![];


while let Some(row) = rows.next().expect("could not read row") {
let id: i64 = row.get(0).expect("could not read id");
let denom: String = row.get(1).expect("could not read denom");
let receiver: String = row.get(2).expect("could not read address");

requests.push(SendRequest { id, receiver, denom, amount: 42 }); //todo fix amount
let Some(coin) = chain.coins.iter().find(|coin| coin.denom == denom) else {
error!(%denom, chain_id=&chain.id, "dropping request for unknown denom");
break;
};


requests.push(SendRequest { id, receiver, denom, amount: coin.amount }); //todo fix amount
}

Ok(requests)
Expand Down Expand Up @@ -493,6 +500,11 @@ impl Mutation {
return Err(format!("invalid chain_id {chain_id}").into());
};

// Ensure denom exists for chain
if !chain.coins.iter().any(|coin| coin.denom == denom) {
return Err(format!("invalid denom {denom}").into());
};

let allow_bypass = bypass_secret
.as_ref()
.is_some_and(|CaptchaBypassSecret(secret)| secret == &captcha_token);
Expand Down

0 comments on commit e80d02a

Please sign in to comment.