Skip to content

Commit d5b3381

Browse files
committed
chore: logs and fixes
1 parent 84097af commit d5b3381

File tree

4 files changed

+98
-51
lines changed

4 files changed

+98
-51
lines changed

cardano/aiken-type-conversion/src/mod.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,24 @@ export function generateType(
88
plutusDefinition: PlutusDefinition,
99
typeDef: AikenType,
1010
): GenType {
11-
const path = typeDef.path;
11+
console.log('typeDef: ' + JSON.stringify(typeDef));
12+
const path = getType(typeDef.path);
13+
14+
let lastPath = "";
15+
if (path != null) {
16+
console.log('path: ' + path);
17+
const path_parts = path.split("/");
18+
lastPath = path_parts[path_parts.length - 1];
19+
console.log('lastPath: ' + lastPath);
20+
}
1221

1322
if (path in builtInTypes) {
14-
return builtInTypes[typeDef.path];
23+
console.log('built in type!')
24+
return builtInTypes[lastPath];
1525
}
1626

27+
console.log('NOT a built in type!')
28+
1729
if ("dataType" in typeDef) {
1830
if (typeDef.dataType == "list" && "items" in typeDef) {
1931
const listType = getPointer(
@@ -131,6 +143,7 @@ export function generateType(
131143

132144
const listType = getPointer(plutusDefinition, cur.$ref);
133145
const genType = generateType(plutusDefinition, listType);
146+
console.log('about to crash 2: ' + genType);
134147

135148
if (genType.type == "primitive") {
136149
schema.push(`${cur.title}: ${genType.schema},`);
@@ -366,6 +379,17 @@ export function generateType(
366379
};
367380
}
368381
}
369-
382+
console.log('about to crash: ' + JSON.stringify(typeDef));
370383
throw new Error("Type is not recognized");
371384
}
385+
386+
function getType(path: string) {
387+
if (path != null && path.indexOf('/') != -1) {
388+
const path_parts = path.split("/");
389+
const lastPath = path_parts[path_parts.length - 1];
390+
console.log('path: ' + path + ' lastPath: ' + lastPath);
391+
return lastPath;
392+
} else {
393+
return path;
394+
}
395+
}

cardano/gateway/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ OGMIOS_ENDPOINT=http://127.0.0.1:1337
1212
CARDANO_CHAIN_HOST=127.0.0.1
1313
CARDANO_CHAIN_PORT=3001
1414
CARDANO_NETWORK_MAGIC=42
15-
CARDANO_EPOCH_NONCE_GENESIS="bf4f4bf6f111f1778bdbe30615f2b6a856412ab7c8669a824465588ba2460e14"
15+
CARDANO_EPOCH_NONCE_GENESIS="3eff1dbf5ab72bb3cf730c0e208468c7299c56bec8fd9871c3e876b67d2d3180"
1616

1717
MITHRIL_ENDPOINT=http://127.0.0.1:8080/aggregator
1818
MITHRIL_GENESIS_VERIFICATION_KEY=5b33322c3235332c3138362c3230312c3137372c31312c3131372c3133352c3138372c3136372c3138312c3138382c32322c35392c3230362c3130352c3233312c3135302c3231352c33302c37382c3231322c37362c31362c3235322c3138302c37322c3133342c3133372c3234372c3136312c36385d

cardano/gateway/src/tx/connection.service.ts

Lines changed: 59 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class ConnectionService {
5353
private readonly logger: Logger,
5454
private configService: ConfigService,
5555
@Inject(LucidService) private lucidService: LucidService,
56-
) {}
56+
) { }
5757
/**
5858
* Processes the connection open init tx.
5959
* @param data The message containing connection open initiation data.
@@ -139,19 +139,27 @@ export class ConnectionService {
139139
*/
140140
async connectionOpenAck(data: MsgConnectionOpenAck): Promise<MsgConnectionOpenAckResponse> {
141141
this.logger.log('Connection Open Ack is processing', 'connectionOpenAck');
142+
this.logger.log(this.prettyPrint(data), 'connectionOpenAck');
142143
try {
144+
143145
const { constructedAddress, connectionOpenAckOperator } = validateAndFormatConnectionOpenAckParams(data);
146+
this.logger.log(this.prettyPrint(connectionOpenAckOperator), 'connectionOpenAck - connectionOpenAckOperator:');
147+
this.logger.log(this.prettyPrint(constructedAddress), 'connectionOpenAck - constructedAddress:');
148+
144149
// Build and complete the unsigned transaction
145150
const unsignedConnectionOpenAckTx: TxBuilder = await this.buildUnsignedConnectionOpenAckTx(
146151
connectionOpenAckOperator,
147152
constructedAddress,
148153
);
154+
this.logger.log(this.prettyPrint(unsignedConnectionOpenAckTx), unsignedConnectionOpenAckTx);
149155
const unsignedConnectionOpenAckTxValidTo: TxBuilder = unsignedConnectionOpenAckTx.validTo(Date.now() + 100 * 1e3);
150156

157+
this.logger.log('post unsignedConnectionOpenAckTxValidTo', 'connectionOpenAck');
151158
// Todo: signing should be done by the relayer in the future
152159
const signedConnectionOpenAckTxCompleted = await (await unsignedConnectionOpenAckTxValidTo.complete()).sign
153160
.withWallet()
154161
.complete();
162+
this.logger.log('post signedConnectionOpenAckTxCompleted', 'connectionOpenAck');
155163

156164
this.logger.log(signedConnectionOpenAckTxCompleted.toHash(), 'connection open ack - unsignedTX - hash');
157165
const response: MsgConnectionOpenAckResponse = {
@@ -390,12 +398,15 @@ export class ConnectionService {
390398
},
391399
};
392400

401+
this.logger.log(this.prettyPrint(spendConnectionRedeemer), 'buildUnsignedConnectionOpenAckTx - spendConnectionRedeemer:')
402+
393403
const connectionDatum: ConnectionDatum = await this.lucidService.decodeDatum<ConnectionDatum>(
394404
connectionUtxo.datum!,
395405
'connection',
396406
);
397407

398408
const clientSequence = parseClientSequence(convertHex2String(connectionDatum.state.client_id));
409+
this.logger.log(this.prettyPrint(clientSequence), 'buildUnsignedConnectionOpenAckTx - clientSequence:')
399410
const updatedConnectionDatum: ConnectionDatum = {
400411
...connectionDatum,
401412
state: {
@@ -407,6 +418,7 @@ export class ConnectionService {
407418
},
408419
},
409420
};
421+
this.logger.log(this.prettyPrint(updatedConnectionDatum), 'buildUnsignedConnectionOpenAckTx - updatedConnectionDatum:')
410422
// Get the token unit associated with the client
411423
const clientTokenUnit = this.lucidService.getClientTokenUnit(clientSequence);
412424
const clientUtxo = await this.lucidService.findUtxoByUnit(clientTokenUnit);
@@ -446,14 +458,17 @@ export class ConnectionService {
446458
},
447459
delay_period: connectionDatum.state.delay_period,
448460
};
461+
this.logger.log(this.prettyPrint(cardanoConnectionEnd), 'buildUnsignedConnectionOpenAckTx - cardanoConnectionEnd:')
449462

450463
const mithrilClientState: MithrilClientState = getMithrilClientStateForVerifyProofRedeemer(
451464
connectionOpenAckOperator.counterpartyClientState,
452465
);
466+
this.logger.log(this.prettyPrint(mithrilClientState), 'buildUnsignedConnectionOpenAckTx - mithrilClientState:')
453467
const mithrilClientStateAny: Any = {
454468
type_url: '/ibc.clients.mithril.v1.ClientState',
455469
value: MithrilClientState.encode(mithrilClientState).finish(),
456470
};
471+
this.logger.log(this.prettyPrint(mithrilClientStateAny), 'buildUnsignedConnectionOpenAckTx - mithrilClientStateAny:')
457472
const verifyProofRedeemer: VerifyProofRedeemer = {
458473
BatchVerifyMembership: [
459474
[
@@ -494,50 +509,17 @@ export class ConnectionService {
494509
],
495510
],
496511
};
512+
this.logger.log(this.prettyPrint(verifyProofRedeemer), 'buildUnsignedConnectionOpenAckTx - verifyProofRedeemer:')
497513

498514
const encodedVerifyProofRedeemer: string = encodeVerifyProofRedeemer(
499515
verifyProofRedeemer,
500516
this.lucidService.LucidImporter,
501517
);
518+
this.logger.log(this.prettyPrint(encodedVerifyProofRedeemer), 'buildUnsignedConnectionOpenAckTx - encodedVerifyProofRedeemer:')
502519

503-
function prettyPrint(obj: any, indent = 2): string {
504-
const seen = new WeakSet();
505-
506-
function replacer(key: string, value: any): any {
507-
// Handle circular references
508-
if (typeof value === 'object' && value !== null) {
509-
if (seen.has(value)) {
510-
return '[Circular Reference]';
511-
}
512-
seen.add(value);
513-
}
514-
515-
// Handle Map objects
516-
if (value instanceof Map) {
517-
const mapEntries: Record<string, any> = {};
518-
value.forEach((v, k) => {
519-
mapEntries[String(k)] = v;
520-
});
521-
return { __type: 'Map', entries: mapEntries };
522-
}
523-
524-
// Handle BigInt values
525-
if (typeof value === 'bigint') {
526-
return { __type: 'BigInt', value: value.toString() };
527-
}
528-
529-
// Handle other special types as needed
530-
// ...
531-
532-
return value;
533-
}
534-
535-
return JSON.stringify(obj, replacer, indent);
536-
}
537-
538-
console.log('verifyProofRedeemer', prettyPrint(verifyProofRedeemer));
539-
console.log('spentConnectionRedeemer', prettyPrint(spendConnectionRedeemer));
540-
console.log('updatedConnectionDatum', prettyPrint(updatedConnectionDatum));
520+
console.log('verifyProofRedeemer', this.prettyPrint(verifyProofRedeemer));
521+
console.log('spentConnectionRedeemer', this.prettyPrint(spendConnectionRedeemer));
522+
console.log('updatedConnectionDatum', this.prettyPrint(updatedConnectionDatum));
541523

542524
const unsignedConnectionOpenAckParams: UnsignedConnectionOpenAckDto = {
543525
connectionUtxo,
@@ -551,6 +533,7 @@ export class ConnectionService {
551533
verifyProofRefUTxO,
552534
encodedVerifyProofRedeemer,
553535
};
536+
console.log('unsignedConnectionOpenAckParams', this.prettyPrint(unsignedConnectionOpenAckParams));
554537
return this.lucidService.createUnsignedConnectionOpenAckTransaction(unsignedConnectionOpenAckParams);
555538
}
556539
/* istanbul ignore next */
@@ -606,4 +589,41 @@ export class ConnectionService {
606589
constructedAddress,
607590
);
608591
}
592+
593+
594+
private prettyPrint(obj: any, indent = 2): string {
595+
const seen = new WeakSet();
596+
597+
function replacer(key: string, value: any): any {
598+
// Handle circular references
599+
if (typeof value === 'object' && value !== null) {
600+
if (seen.has(value)) {
601+
return '[Circular Reference]';
602+
}
603+
seen.add(value);
604+
}
605+
606+
// Handle Map objects
607+
if (value instanceof Map) {
608+
const mapEntries: Record<string, any> = {};
609+
value.forEach((v, k) => {
610+
mapEntries[String(k)] = v;
611+
});
612+
return { __type: 'Map', entries: mapEntries };
613+
}
614+
615+
// Handle BigInt values
616+
if (typeof value === 'bigint') {
617+
return { __type: 'BigInt', value: value.toString() };
618+
}
619+
620+
// Handle other special types as needed
621+
// ...
622+
623+
return value;
624+
}
625+
626+
return JSON.stringify(obj, replacer, indent);
627+
}
628+
609629
}

caribic/src/utils.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use indicatif::{ProgressBar, ProgressStyle};
88
use regex::Regex;
99
use reqwest::Client;
1010
use serde_json::Value;
11-
use std::{collections::HashMap, fs};
1211
use std::fs::File;
1312
use std::fs::Permissions;
1413
use std::io::BufRead;
@@ -18,6 +17,7 @@ use std::os::unix::fs::PermissionsExt;
1817
use std::path::{Path, PathBuf};
1918
use std::process::{Command, Stdio};
2019
use std::time::Duration;
20+
use std::{collections::HashMap, fs};
2121
use std::{collections::VecDeque, thread};
2222
use std::{error::Error, process::Output};
2323
use tokio::io::AsyncWriteExt;
@@ -505,6 +505,12 @@ pub fn get_osmosis_dir(project_root: &Path) -> PathBuf {
505505
.to_path_buf()
506506
}
507507

508+
// return Some(
509+
// String::from_utf8_lossy(&output.stdout)
510+
// .split(' ')
511+
// .collect::<Vec<_>>()[1]
512+
// .to_string(),
513+
// );
508514
pub fn extract_tendermint_client_id(output: Output) -> Option<String> {
509515
if output.status.success() {
510516
let regex = Regex::new(r#"client_id:\s*ClientId\(\s*"([^"]+)""#).unwrap();
@@ -536,7 +542,7 @@ pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<
536542
for entry in fs::read_dir(src)? {
537543
let entry = entry?;
538544
let file_type = entry.file_type()?;
539-
545+
540546
// Get the source and destination paths
541547
let src_path = entry.path();
542548
let dst_path = dst.as_ref().join(entry.file_name());
@@ -552,7 +558,7 @@ pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<
552558
Ok(())
553559
}
554560

555-
pub fn query_balance(project_root_path: &Path, address: &str,) -> u64 {
561+
pub fn query_balance(project_root_path: &Path, address: &str) -> u64 {
556562
let cardano_dir = project_root_path.join("chains/cardano");
557563

558564
let cardano_cli_args = vec!["compose", "exec", "cardano-node", "cardano-cli"];
@@ -576,10 +582,7 @@ pub fn query_balance(project_root_path: &Path, address: &str,) -> u64 {
576582
let v: HashMap<String, Value> =
577583
serde_json::from_str(String::from_utf8(balance).unwrap().as_str()).unwrap();
578584

579-
v
580-
.values()
585+
v.values()
581586
.map(|k| k["value"]["lovelace"].as_u64().unwrap())
582587
.sum()
583-
584-
585-
}
588+
}

0 commit comments

Comments
 (0)