Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft PR to avoid branch pruning #1035

Draft
wants to merge 159 commits into
base: release/cuttlefish
Choose a base branch
from
Draft
Changes from 20 commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
0451b01
Add MeshApi v1.4.15 schema
lrubasze Oct 31, 2024
21db3e2
Add generated openapi server
lrubasze Oct 31, 2024
4badcac
mesh-api-server initial implementation
lrubasze Oct 31, 2024
beb0172
MeshApi support in Java part
lrubasze Oct 30, 2024
22e1e2c
Adjust errors to MeshApi requirements
lrubasze Oct 31, 2024
73086f4
Add network/status endpoint
lrubasze Oct 31, 2024
d7a19a0
Add network/list endpoint
lrubasze Nov 4, 2024
386d221
Refactor error reporting
lrubasze Nov 4, 2024
b493069
Add network/options endpoint
lrubasze Nov 4, 2024
2a5a38d
Assume block is a single transaction
lrubasze Nov 4, 2024
e583d77
Add account/balance endpoint
lrubasze Nov 5, 2024
b11d85e
Hardcode node version
lrubasze Nov 5, 2024
1aac9ea
Unsupport historical balance querying
lrubasze Nov 5, 2024
76c4451
Use index as hash in block identifier
lrubasze Nov 5, 2024
3cc82f3
Add endpoint stubs
lrubasze Nov 5, 2024
e3a4e6c
Fix formatting
lrubasze Nov 5, 2024
bdf71f0
Add mesh-api-server to Dockerfile
lrubasze Nov 5, 2024
8b8c4a1
Block identifier conversions improved
lrubasze Nov 6, 2024
f1fdeff
Cleanup
lrubasze Nov 6, 2024
ae467e3
Cleanup OpenAPI generation scripts
lrubasze Nov 6, 2024
a7e617a
Cleanup TODO notes
lrubasze Nov 6, 2024
322ee34
Tweak network status response
lrubasze Nov 6, 2024
34c4379
Add more TODOs
lrubasze Nov 6, 2024
5bb0067
Tweak network status response
lrubasze Nov 6, 2024
56b4153
Some renaming
lrubasze Nov 6, 2024
ceaeac3
Fix Currency <-> ResourceAddress conversion
lrubasze Nov 6, 2024
74af262
Add extract_account
lrubasze Nov 6, 2024
205fea7
Add support for node version fetching
lrubasze Nov 6, 2024
81bf9da
Remove FeatureNotEnabled error
lrubasze Nov 6, 2024
07045b1
Cleanup
lrubasze Nov 6, 2024
008779b
Fix formatting
lrubasze Nov 6, 2024
522e23e
Cleanup warnings
lrubasze Nov 6, 2024
c9302a6
Fix network endpoints
lrubasze Nov 6, 2024
ebe526a
Update default.config.envsubst
lrubasze Nov 7, 2024
518d94f
Conditionally start MeshAPI server
lrubasze Nov 7, 2024
ddee0b8
Rework timestamp_start_index getting
lrubasze Nov 7, 2024
272afd5
Assert subnetworks
lrubasze Nov 7, 2024
7f2b65e
Assert account in extract_account
lrubasze Nov 7, 2024
7164fe8
Add mesh-cli tests to CI
iamyulong Nov 6, 2024
b5acc27
MeshApi - Scaffolding (#1013)
lrubasze Nov 7, 2024
448f409
Feature/add mesh cli tests (#1014)
iamyulong Nov 7, 2024
ca306cd
Add construct derive
iamyulong Nov 7, 2024
782a606
Add construction preprocess & metadata
iamyulong Nov 7, 2024
a5f87c5
Implement /block endpoint
lrubasze Nov 6, 2024
b99fd78
Fix account balance
lrubasze Nov 7, 2024
9dea949
Handle invalid timestamps
lrubasze Nov 8, 2024
92d17ab
Fix failed transactions reporting
lrubasze Nov 8, 2024
4382ce6
/block/transaction endpoint
lrubasze Nov 8, 2024
ae4bf85
Configure rosetta-cli test dir and test end condition
lrubasze Nov 8, 2024
c4ba45a
Add construction payloads endpoint
iamyulong Nov 7, 2024
51a293a
Fix mesh-cli CI
lrubasze Nov 8, 2024
b18daae
Some cleanup
lrubasze Nov 8, 2024
c971a8d
Workaround empty node version
lrubasze Nov 8, 2024
febcea0
Run node in daemon mode
lrubasze Nov 8, 2024
edd5a24
Set localhost when running node in CI
lrubasze Nov 8, 2024
e95e395
Restore mesh-cli node setup
lrubasze Nov 8, 2024
4aea4d0
Add construction parse endpoint
iamyulong Nov 8, 2024
edd2295
Add construction hash endpoint
iamyulong Nov 8, 2024
3b26b9b
Add combine & submit endpoints
iamyulong Nov 8, 2024
4a07672
Revert "Workaround empty node version"
lrubasze Nov 8, 2024
ea9942a
ApplicationVersion - fallback to defaults if properties are empty str…
lrubasze Nov 8, 2024
fb9fbb9
Fix partial block conversion
lrubasze Nov 11, 2024
9ea54b7
Some cleanup
lrubasze Nov 11, 2024
e626ddb
Some comments
lrubasze Nov 11, 2024
cd602e4
TODO added
lrubasze Nov 11, 2024
7df3a9d
Bump deps for docker images
lrubasze Nov 11, 2024
6ef0ffc
TODO added
lrubasze Nov 11, 2024
7ee28b9
Stub mempool implementation
lrubasze Nov 11, 2024
d29527b
Merge remote-tracking branch 'origin/develop' into feature/mesh-api-m…
lrubasze Nov 11, 2024
547957a
Feature/mesh api block (#1018)
lrubasze Nov 11, 2024
df86f22
Merge remote-tracking branch 'origin/feature/mesh' into feature/const…
iamyulong Nov 11, 2024
4b4086c
Add MeshAPI mempool test
lrubasze Nov 11, 2024
338e6ce
Implement mempool endpoint
lrubasze Nov 11, 2024
c5d5b36
Implement mempool/transaction endpoint
lrubasze Nov 11, 2024
066d14f
Add MeshAPI mempool/transaction test
lrubasze Nov 11, 2024
56b8531
Update workflows
iamyulong Nov 11, 2024
86767bd
Tweak mempool tests
lrubasze Nov 12, 2024
2ac2616
Update workflows
iamyulong Nov 12, 2024
3b6af37
Update construction endpoints
iamyulong Nov 12, 2024
df43df4
Update workflows
iamyulong Nov 12, 2024
16028d3
Update transaction submit
iamyulong Nov 12, 2024
4e57a59
Clean up code
iamyulong Nov 12, 2024
5c6908c
Update CI
iamyulong Nov 12, 2024
9fd6ba0
Fix typo
iamyulong Nov 12, 2024
65473e8
Revert CI change
iamyulong Nov 13, 2024
add63fe
Feature/mesh api mempool (#1019)
lrubasze Nov 13, 2024
92acbbe
Tweak stale_depth and broadcast_limit
iamyulong Nov 13, 2024
c86ce2f
Remove binary
iamyulong Nov 13, 2024
4cb91a4
Merge remote-tracking branch 'origin/feature/mesh' into feature/const…
iamyulong Nov 13, 2024
f75dbf8
Add construction API endpoints (#1022)
iamyulong Nov 13, 2024
902846b
Merge remote-tracking branch 'origin/develop' into feature/mesh
iamyulong Nov 13, 2024
b3b7d27
Fix merge errors
iamyulong Nov 13, 2024
254d6d2
Move fee payment computations to node-common
lrubasze Nov 12, 2024
d5c2aaf
Add fee support to MeshAPI block endpoints
lrubasze Nov 12, 2024
69e5992
Fix MeshApiOperationTypes
lrubasze Nov 13, 2024
628edcd
Lock fee from implicit sender
iamyulong Nov 13, 2024
bc1e1e2
Use negative for withdraw amount
iamyulong Nov 13, 2024
6e4579c
Temporarily unsupport fee operations
lrubasze Nov 14, 2024
552cbad
Warnings cleanup
lrubasze Nov 14, 2024
f7866ed
Fix error message
lrubasze Nov 14, 2024
0a563c5
Fix mempool test
lrubasze Nov 14, 2024
5667cf9
MeshAPI - support non-user transactions (#1024)
lrubasze Nov 15, 2024
a6dd4e0
Update engine dependencies for upgraded wasmi
iamyulong Nov 15, 2024
4493114
Merge remote-tracking branch 'origin/develop' into feature/mesh
iamyulong Nov 15, 2024
ad4f966
Add spec tests to CI
lrubasze Nov 15, 2024
8fba923
Fetching balances improved
lrubasze Nov 15, 2024
20fc115
Update rust version
iamyulong Nov 15, 2024
c042e54
Feature/update rust (#1028)
iamyulong Nov 15, 2024
3e25205
Update rust version
iamyulong Nov 15, 2024
fda3e68
Removed TODO from balance exemptions
lrubasze Nov 15, 2024
763585b
Feature/mesh cleanups (#1027)
lrubasze Nov 15, 2024
a12ba95
Merge branch 'develop' into feature/mesh
lrubasze Nov 15, 2024
3d03cd0
Merge branch 'release/cuttlefish' into release/cuttlefish-wasmi-upgrade
iamyulong Nov 15, 2024
4f7aa04
Bump engine dependencies
iamyulong Nov 15, 2024
6cf9cb7
Merge remote-tracking branch 'origin/develop' into feature/mesh
iamyulong Nov 15, 2024
1f89f0c
Clean up error in conventions mod
iamyulong Nov 15, 2024
6e03a72
Clean up construction errors
iamyulong Nov 15, 2024
e4f2720
Setup workflow in separate scenario
lrubasze Nov 18, 2024
d87b52d
More error cleanup
lrubasze Nov 18, 2024
e0050aa
Remove not used errors
lrubasze Nov 18, 2024
93c5c76
Revert "Setup workflow in separate scenario"
lrubasze Nov 18, 2024
7003fc7
Workaround mesh-cli DSL parsing error
lrubasze Nov 19, 2024
2753ec2
Mempool tests cleanup
lrubasze Nov 20, 2024
0c4aa93
Merge remote-tracking branch 'origin/release/cuttlefish' into develop
iamyulong Nov 21, 2024
36bca03
Some cleanup
lrubasze Nov 20, 2024
46cebc9
TODOs added
lrubasze Nov 20, 2024
d37c370
More cleanup
lrubasze Nov 21, 2024
9e03a3b
Reimplement block hash
lrubasze Nov 21, 2024
44bc046
Reimplement transaction identifier for non-user transactions
lrubasze Nov 21, 2024
df784c5
Cleanup
lrubasze Nov 21, 2024
c8c5f33
Merge branch 'develop' into feature/mesh
lrubasze Nov 21, 2024
b8f3151
Feature: Mesh API Implementation (#1021)
iamyulong Nov 21, 2024
1251e85
Enable historical balances for Mesh
lrubasze Nov 19, 2024
ea3fc65
Support fee payments
lrubasze Nov 19, 2024
020d4c0
Support only FeePayment type
lrubasze Nov 20, 2024
0465299
Check if history enabled in runtime
lrubasze Nov 22, 2024
bc0abcf
Add mesh-cli configs for stokenet and mainnet
lrubasze Nov 22, 2024
694a2a4
Add Mesh API readme
lrubasze Nov 26, 2024
d62e0b7
Remove TODO from Mesh API metrics
lrubasze Nov 26, 2024
d5b2a9e
Parse operations for mempool transactions
lrubasze Nov 27, 2024
2f80d02
Update CI
lrubasze Nov 28, 2024
9684fe5
Cleanup
lrubasze Nov 28, 2024
b043d27
Update Readme
lrubasze Nov 28, 2024
0ac415f
Remove TODOs
lrubasze Nov 28, 2024
323538d
Fix MeshApiMempoolEndpointsTest
lrubasze Nov 29, 2024
8df5dd3
Add numeric conversion tests
lrubasze Nov 29, 2024
50fdd19
Update Mesh readme
lrubasze Dec 9, 2024
1950e4e
Assume successful operations only
lrubasze Dec 9, 2024
3f20511
Update some comments
lrubasze Dec 9, 2024
5b0d1bf
Rename error
lrubasze Dec 9, 2024
486f539
Tune InvalidTransaction messages
lrubasze Dec 9, 2024
0e5f5fb
Add Mesh API bind address in testnet node setup
lrubasze Dec 10, 2024
ac6660e
Add Mesh instructions for docker
lrubasze Dec 10, 2024
5fca792
Replace dyn Trait objects with impl Trait for better performance
lrubasze Dec 10, 2024
95b0ed7
Use ActualStateManagerDatabase in Mesh API
lrubasze Dec 10, 2024
26e8eb2
Revert "Use ActualStateManagerDatabase in Mesh API"
lrubasze Dec 10, 2024
0d2b11b
Enable Mesh API in testnet-node
lrubasze Dec 10, 2024
8de4789
Address some comments
lrubasze Dec 10, 2024
6cb8f0a
Mesh reconciliation tests support (#1036)
lrubasze Dec 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -249,8 +249,6 @@ jobs:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Install mesh-cli
run: curl -sSfL https://raw.githubusercontent.com/coinbase/mesh-cli/master/scripts/install.sh | sh -s
- name: Build Node
run: ./gradlew build
- name: Run Node in the background
@@ -260,8 +258,12 @@ jobs:
run: ./gradlew :core:run --info &
- name: Wait for 2 minutes
run: sleep 2m
- name: Run mesh-cli tests (TODO:MESH add other checks)
- name: Install mesh-cli
run: curl -sSfL https://raw.githubusercontent.com/coinbase/mesh-cli/master/scripts/install.sh | sh -s
- name: Run Data API tests
run: ./bin/rosetta-cli check:data --configuration-file core-rust/mesh-api-server/mesh-cli-configs/default.json
- name: Run Construction API tests
run: ./bin/rosetta-cli check:construction --configuration-file core-rust/mesh-api-server/mesh-cli-configs/default.json
cross-xwin:
name: Cross compile to Windows
runs-on: ubuntu-latest
33 changes: 27 additions & 6 deletions core-rust/mesh-api-server/mesh-cli-configs/default.json
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
"blockchain": "radix",
"network": "localnet"
},
"online_url": "http://localhost:3337/mesh",
"online_url": "http://127.0.0.1:3337/mesh",
"data_directory": "test-data",
"http_timeout": 10,
"max_retries": 5,
@@ -40,12 +40,33 @@
"pruning_block_disabled": false,
"pruning_balance_disabled": false,
"initial_balance_fetch_disabled": false,
"end_conditions":{
"tip":true,
"index": 10000
"end_conditions": {
"tip": true,
"index": 10000
}
},
"construction": {
"offline_url": "http://127.0.0.1:3337/mesh",
"constructor_dsl_file": "workflows.ros",
"prefunded_accounts": [
{
"account_identifier": {
"address": "account_loc16996e320lnez82q6430eunaz9l3n5fnwk6eh9avrmtmj22e7rd55ln"
},
"curve_type": "secp256k1",
"privkey": "000000000000000000000000000000000000000000000000000000000000821f",
"currency": {
"symbol": "resource_loc1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxvq32hv",
"decimals": 18
}
}
],
"stale_depth": 1000,
"broadcast_limit": 1000,
"end_conditions": {
"radix_workflow": 1
}
},
"construction": null,
"perf": null,
"sign": null
}
}
67 changes: 67 additions & 0 deletions core-rust/mesh-api-server/mesh-cli-configs/workflows.ros
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
radix_workflow(1){
create_account{
network = {"network":"localnet", "blockchain":"radix"};
key = generate_key({"curve_type":"secp256k1"});
recipient = derive({
"network_identifier": {{network}},
"public_key": {{key.public_key}}
});
save_account({
"account_identifier": {{recipient.account_identifier}},
"keypair": {{key}}
});
print_message("recipient:");
print_message({{recipient}});
},
transfer{
currency = {"symbol":"resource_loc1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxvq32hv", "decimals":18};
min_balance = "1111000000000000000000";

sender = find_balance({
"minimum_balance":{
"value": {{min_balance}},
"currency": {{currency}}
}
});
print_message("sender:");
print_message({{sender}});

fee_amount = "22000000000000000000";
transfer_amount = "33000000000000000000";

transfer.confirmation_depth = "1";
transfer.network = {{network}};
transfer.operations = [
{
"operation_identifier":{"index":0},
"type":"LockFee",
"account":{{sender.account_identifier}},
"amount":{
"value":{{fee_amount}},
"currency":{{currency}}
}
},
{
"operation_identifier":{"index":1},
"type":"Withdraw",
"account":{{sender.account_identifier}},
"amount":{
"value":{{transfer_amount}},
"currency":{{currency}}
}
},
{
"operation_identifier":{"index":2},
"type":"Deposit",
"account":{{recipient.account_identifier}},
"amount":{
"value":{{transfer_amount}},
"currency":{{currency}}
}
}
];

print_message("transfer:");
print_message({{transfer}});
}
}
1 change: 1 addition & 0 deletions core-rust/mesh-api-server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -75,6 +75,7 @@ pub(crate) mod prelude {
pub(crate) use state_manager::prelude::*;

pub(crate) use crate::mesh_api::*;
pub(crate) use borrow::Borrow;
pub(crate) use historical_state::*;

// Axum imports
Original file line number Diff line number Diff line change
@@ -97,6 +97,19 @@ pub fn extract_account(
}
}

pub fn extract_account_from_option(
extraction_context: &ExtractionContext,
account_identifier: Option<Box<crate::mesh_api::generated::models::AccountIdentifier>>,
) -> Result<ComponentAddress, ResponseError> {
extract_account(
extraction_context,
account_identifier
.ok_or(client_error("Missing account", false))?
.borrow(),
)
.map_err(|e| client_error(format!("Failed to extract account: {e:?}"), false))
}

pub fn to_mesh_api_currency_from_resource_address(
mapping_context: &MappingContext,
database: &StateManagerDatabase<impl ReadableRocks>,
67 changes: 67 additions & 0 deletions core-rust/mesh-api-server/src/mesh_api/conversions/crypto.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use crate::prelude::*;
use models::SignatureType;

pub(crate) fn extract_public_key(
public_key: &crate::mesh_api::generated::models::PublicKey,
) -> Result<PublicKey, ResponseError> {
match public_key.curve_type {
models::CurveType::Secp256k1 => Ok(PublicKey::Secp256k1(
hex::decode(&public_key.hex_bytes)
.ok()
.and_then(|bytes| Secp256k1PublicKey::try_from(bytes.as_slice()).ok())
.ok_or(client_error(
format!("Invalid Secp256k1 public key: {}", public_key.hex_bytes),
false,
))?,
)),
models::CurveType::Edwards25519 => Ok(PublicKey::Ed25519(
hex::decode(&public_key.hex_bytes)
.ok()
.and_then(|bytes| Ed25519PublicKey::try_from(bytes.as_slice()).ok())
.ok_or(client_error(
format!("Invalid Ed25519 public key: {}", public_key.hex_bytes),
false,
))?,
)),
_ => Err(client_error(
format!("Invalid curve type: {:?}", &public_key.curve_type),
false,
)),
}
}

pub(crate) fn extract_signature(
signature: &crate::mesh_api::generated::models::Signature,
) -> Result<SignatureV1, ResponseError> {
match signature.signature_type {
SignatureType::EcdsaRecovery => Ok(SignatureV1::Secp256k1(
hex::decode(&signature.hex_bytes)
.ok()
.and_then(|mut bytes| {
// Mesh uses r + s + v
// Radix uses v + r + s
if let Some(v) = bytes.pop() {
bytes.insert(0, v);
}
Secp256k1Signature::try_from(bytes.as_slice()).ok()
})
.ok_or(client_error(
format!("Invalid Secp256k1 signature: {}", signature.hex_bytes),
false,
))?,
)),
SignatureType::Ed25519 => Ok(SignatureV1::Ed25519(
hex::decode(&signature.hex_bytes)
.ok()
.and_then(|bytes| Ed25519Signature::try_from(bytes.as_slice()).ok())
.ok_or(client_error(
format!("Invalid Ed25519 signature: {}", signature.hex_bytes),
false,
))?,
)),
_ => Err(client_error(
format!("Invalid signature type: {:?}", &signature.signature_type),
false,
)),
}
}
2 changes: 2 additions & 0 deletions core-rust/mesh-api-server/src/mesh_api/conversions/mod.rs
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ mod addressing;
mod block;
mod common;
mod context;
mod crypto;
mod errors;
mod hashes;
mod numerics;
@@ -10,6 +11,7 @@ pub use addressing::*;
pub use block::*;
pub use common::*;
pub use context::*;
pub use crypto::*;
pub use errors::*;
pub use hashes::*;
pub use numerics::*;
47 changes: 47 additions & 0 deletions core-rust/mesh-api-server/src/mesh_api/conversions/numerics.rs
Original file line number Diff line number Diff line change
@@ -169,3 +169,50 @@ pub fn to_mesh_api_amount(

Ok(models::Amount::new(value.attos().to_string(), currency))
}

pub(crate) fn extract_amount(
extraction_context: &ExtractionContext,
amount: &models::Amount,
) -> Result<(ResourceAddress, Decimal), ResponseError> {
let address = ResourceAddress::try_from_bech32(
&extraction_context.address_decoder,
&amount.currency.symbol,
)
.ok_or(client_error(
format!("Invalid resource address: {:?}", amount.currency.symbol),
false,
))?;

let scale = if amount.currency.decimals < 0 || amount.currency.decimals > 18 {
return Err(client_error(
format!("Invalid decimals: {}", amount.currency.decimals),
false,
));
} else {
dec!(10)
.checked_powi(amount.currency.decimals as i64)
.unwrap()
};

let quantity = Decimal::from_str(&amount.value)
.ok()
.and_then(|x| x.checked_div(scale))
.ok_or(client_error(
format!("Invalid quantity: {:?}", amount.value),
false,
))?;

Ok((address, quantity))
}

pub(crate) fn extract_amount_from_option(
extraction_context: &ExtractionContext,
amount: Option<Box<crate::mesh_api::generated::models::Amount>>,
) -> Result<(ResourceAddress, Decimal), ResponseError> {
extract_amount(
extraction_context,
amount
.ok_or(client_error("Missing amount", false))?
.borrow(),
)
}
11 changes: 8 additions & 3 deletions core-rust/mesh-api-server/src/mesh_api/errors.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use crate::prelude::*;
use std::any::Any;

use hyper::StatusCode;

use rand::distributions::Alphanumeric;
use rand::Rng;
use std::any::Any;
use strum::{Display, EnumIter, IntoEnumIterator};
use tower_http::catch_panic::ResponseForPanic;

@@ -202,3 +200,10 @@ pub(crate) fn assert_matching_network(
}
Ok(())
}

// TODO:MESH - Add logging, metrics and tracing for all of these errors - require the error is passed in here
pub(crate) fn client_error(message: impl Into<String>, retriable: bool) -> ResponseError {
ResponseError::from(ApiError::InvalidRequest)
.retriable(retriable)
.with_details(message)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use crate::prelude::*;

pub(crate) async fn handle_construction_combine(
state: State<MeshApiState>,
Json(request): Json<models::ConstructionCombineRequest>,
) -> Result<Json<models::ConstructionCombineResponse>, ResponseError> {
assert_matching_network(&request.network_identifier, &state.network)?;

let signature = if request.signatures.len() == 1 {
extract_signature(&request.signatures[0])?
} else {
return Err(client_error(
format!(
"Expected 1 signature, but received {}",
request.signatures.len()
),
false,
));
};

let intent = RawTransactionIntent::from_hex(&request.unsigned_transaction)
.ok()
.and_then(|x| IntentV1::from_raw(&x).ok())
.ok_or(client_error(
format!(
"Invalid unsigned transaction: {}",
&request.unsigned_transaction
),
false,
))?;
let tx = NotarizedTransactionV1 {
signed_intent: SignedIntentV1 {
intent,
intent_signatures: IntentSignaturesV1 {
signatures: Vec::new(),
},
},
notary_signature: NotarySignatureV1(signature),
};

// See https://docs.cdp.coinbase.com/mesh/docs/models#constructioncombineresponse for field
// definitions
Ok(Json(models::ConstructionCombineResponse {
signed_transaction: hex::encode(tx.to_raw().unwrap()),
}))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use crate::prelude::*;
use models::AccountIdentifier;

pub(crate) async fn handle_construction_derive(
state: State<MeshApiState>,
Json(request): Json<models::ConstructionDeriveRequest>,
) -> Result<Json<models::ConstructionDeriveResponse>, ResponseError> {
assert_matching_network(&request.network_identifier, &state.network)?;

let public_key = extract_public_key(&request.public_key)?;
let address = state.public_key_to_address(public_key);

// See https://docs.cdp.coinbase.com/mesh/docs/models#constructionderiveresponse for field
// definitions
Ok(Json(models::ConstructionDeriveResponse {
address: None, // deprecated
account_identifier: Some(Box::new(AccountIdentifier {
address,
sub_account: None,
metadata: None,
})),
metadata: None,
}))
}
Loading
Loading