Skip to content

Commit e3e18e5

Browse files
authored
Merge pull request #761 from openmina/feat/o1js-graphql
GraphQL endpoints for o1js
2 parents 908e673 + 708acef commit e3e18e5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3665
-517
lines changed

Cargo.lock

Lines changed: 124 additions & 214 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ serde_json = "1.0.107"
5353
serde_with = { version = "3.7.0", features = ["hex"] }
5454
linkme = "0.3.22"
5555
static_assertions = "1.1.0"
56+
juniper = { version = "0.16" }
57+
5658

5759
[profile.fuzz]
5860
inherits = "release"

core/src/consensus.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use mina_p2p_messages::v2::{
33
ConsensusProofOfStakeDataConsensusStateValueStableV2 as MinaConsensusState, StateHash,
44
};
55
use serde::{Deserialize, Serialize};
6+
use time::{macros::format_description, OffsetDateTime};
67

78
use crate::constants::constraint_constants;
89
pub use crate::constants::{
@@ -301,6 +302,13 @@ impl ConsensusConstants {
301302
constants.assert_invariants();
302303
constants
303304
}
305+
306+
pub fn human_readable_genesis_timestamp(&self) -> Result<String, String> {
307+
let format = format_description!("[year]-[month]-[day]T[hour]:[minute]:[second].[subsecond digits:6][offset_hour sign:mandatory]:[offset_minute]");
308+
OffsetDateTime::from_unix_timestamp((self.genesis_state_timestamp.as_u64() / 1000) as i64)
309+
.map_err(|e| e.to_string())
310+
.and_then(|dt| dt.format(&format).map_err(|e| e.to_string()))
311+
}
304312
}
305313

306314
#[cfg(test)]

core/src/dummy/mod.rs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::sync::Arc;
22

3-
use binprot::BinProtRead;
43
use mina_p2p_messages::v2::{MinaBaseProofStableV2, TransactionSnarkProofStableV2};
54

5+
// NOTE: moved to mina_p2p_messages crate
66
/// Value of `Proof.transaction_dummy` when we run `dune runtest src/lib/staged_ledger -f`
77
/// The file was generated this way:
88
///
@@ -19,28 +19,10 @@ use mina_p2p_messages::v2::{MinaBaseProofStableV2, TransactionSnarkProofStableV2
1919
/// Core.Printf.eprintf !"dummy proof= %{sexp: Proof.t}\n%!" dummy;
2020
/// Core.Printf.eprintf !"dummy proof= %s\n%!" s;
2121
pub fn dummy_transaction_proof() -> Arc<TransactionSnarkProofStableV2> {
22-
lazy_static::lazy_static! {
23-
static ref DUMMY_PROOF: Arc<TransactionSnarkProofStableV2> = {
24-
let bytes = include_bytes!("dummy_transaction_proof.bin");
25-
TransactionSnarkProofStableV2::binprot_read(&mut bytes.as_slice())
26-
.unwrap()
27-
.into()
28-
};
29-
}
30-
31-
DUMMY_PROOF.clone()
22+
mina_p2p_messages::v2::dummy_transaction_proof()
3223
}
3324

3425
/// Value of `Proof.blockchain_dummy`
3526
pub fn dummy_blockchain_proof() -> Arc<MinaBaseProofStableV2> {
36-
lazy_static::lazy_static! {
37-
static ref DUMMY_PROOF: Arc<MinaBaseProofStableV2> = {
38-
let bytes = include_bytes!("dummy_blockchain_proof.bin");
39-
MinaBaseProofStableV2::binprot_read(&mut bytes.as_slice())
40-
.unwrap()
41-
.into()
42-
};
43-
}
44-
45-
DUMMY_PROOF.clone()
27+
mina_p2p_messages::v2::dummy_blockchain_proof()
4628
}

frontend/src/assets/environments/compose.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ export default {
88
state: ['actions'],
99
network: ['node-dht', 'graph-overview', 'bootstrap-stats'],
1010
snarks: ['scan-state'],
11+
benchmarks: ['wallets'],
1112
},
1213
canAddNodes: true,
14+
graphQL: '/openmina-node/graphql',
1315
},
1416
configs: [
1517
{

frontend/src/environments/environment.compose.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const environment: Readonly<MinaEnv> = {
1010
state: ['actions'],
1111
network: ['node-dht', 'graph-overview', 'bootstrap-stats'],
1212
snarks: ['scan-state'],
13+
benchmarks: ['wallets'],
1314
},
1415
canAddNodes: true,
1516
},

ledger/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ o1-utils = { workspace = true }
2626
kimchi = { workspace = true }
2727
mina-poseidon = { workspace = true }
2828
poly-commitment = { workspace = true }
29+
juniper = { workspace = true }
2930
openmina-macros = { path = "../macros" }
31+
strum = "0.26.2"
32+
strum_macros = "0.26.4"
3033

3134
bs58 = "0.4.0"
3235
mina-p2p-messages = { workspace = true }

ledger/src/account/account.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,12 @@ pub struct VerificationKey {
419419
pub wrap_vk: Option<()>,
420420
}
421421

422+
// impl From<VerificationKey> for MinaBaseVerificationKeyWireStableV1Base64 {
423+
// fn from(value: VerificationKey) -> Self {
424+
// MinaBaseVerificationKeyWireStableV1Base64((&value).into())
425+
// }
426+
// }
427+
422428
impl Check<Fp> for VerificationKey {
423429
fn check(&self, w: &mut Witness<Fp>) {
424430
let Self {

ledger/src/account/common.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ impl VotingFor {
4141
let state_hash = mina_p2p_messages::v2::StateHash::from_fp(self.0);
4242
state_hash.to_string()
4343
}
44+
45+
pub fn to_base58check_graphql(&self) -> String {
46+
// NOTE: See https://github.com/MinaProtocol/mina/blob/fb1c3c0a408c344810140bdbcedacc532a11be91/src/lib/mina_graphql/types.ml#L1528
47+
let receipt_chain_hash = ReceiptChainHash(self.0);
48+
let receipt_chain_hash = mina_p2p_messages::v2::ReceiptChainHash::from(receipt_chain_hash);
49+
receipt_chain_hash.to_string()
50+
}
4451
}
4552

4653
#[test]
@@ -241,7 +248,7 @@ impl Default for TokenPermissions {
241248
}
242249

243250
// https://github.com/MinaProtocol/mina/blob/develop/src/lib/mina_base/permissions.mli#L10
244-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
251+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, strum_macros::Display)]
245252
#[serde(rename_all = "lowercase")]
246253
pub enum AuthRequired {
247254
None,

ledger/src/account/conv.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(clippy::type_complexity)]
22

33
use ark_ec::short_weierstrass_jacobian::GroupAffine;
4-
use ark_ff::{fields::arithmetic::InvalidBigInt, Field};
4+
use ark_ff::{fields::arithmetic::InvalidBigInt, Field, PrimeField};
55
use mina_hasher::Fp;
66
use mina_p2p_messages::{
77
bigint::BigInt,
@@ -11,8 +11,9 @@ use mina_p2p_messages::{
1111
self, MinaBaseAccountBinableArgStableV2, MinaBaseAccountIdDigestStableV1,
1212
MinaBaseAccountIdStableV2, MinaBaseAccountIndexStableV1, MinaBaseAccountTimingStableV2,
1313
MinaBasePermissionsAuthRequiredStableV2, MinaBasePermissionsStableV2,
14-
MinaBaseVerificationKeyWireStableV1, MinaBaseVerificationKeyWireStableV1WrapIndex,
15-
NonZeroCurvePointUncompressedStableV1, PicklesBaseProofsVerifiedStableV1, TokenIdKeyHash,
14+
MinaBaseReceiptChainHashStableV1, MinaBaseVerificationKeyWireStableV1,
15+
MinaBaseVerificationKeyWireStableV1WrapIndex, NonZeroCurvePointUncompressedStableV1,
16+
PicklesBaseProofsVerifiedStableV1, TokenIdKeyHash,
1617
},
1718
};
1819

@@ -56,6 +57,12 @@ impl From<TokenId> for TokenIdKeyHash {
5657
}
5758
}
5859

60+
impl From<TokenIdKeyHash> for TokenId {
61+
fn from(value: TokenIdKeyHash) -> Self {
62+
value.inner().try_into().unwrap()
63+
}
64+
}
65+
5966
impl<F: FieldWitness> TryFrom<(BigInt, BigInt)> for InnerCurve<F>
6067
where
6168
F: Field + From<BigInt>,
@@ -642,6 +649,12 @@ impl From<AccountIndex> for MinaBaseAccountIndexStableV1 {
642649
}
643650
}
644651

652+
impl From<ReceiptChainHash> for mina_p2p_messages::v2::ReceiptChainHash {
653+
fn from(value: ReceiptChainHash) -> Self {
654+
MinaBaseReceiptChainHashStableV1(value.0.into_repr().into()).into()
655+
}
656+
}
657+
645658
#[cfg(test)]
646659
mod tests {
647660
use super::*;

0 commit comments

Comments
 (0)