-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: replace cardano-cli per ogmios
- Loading branch information
Juan Cruz
committed
May 30, 2022
1 parent
b5c89d4
commit 477e82b
Showing
15 changed files
with
99 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "cardano-rosetta-server/ogmios"] | ||
path = cardano-rosetta-server/ogmios | ||
url = https://github.com/CardanoSolutions/ogmios |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
cardano-rosetta-server/src/server/controllers/network-controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 0 additions & 89 deletions
89
cardano-rosetta-server/src/server/utils/cardano/cli/cardanonode-client.ts
This file was deleted.
Oops, something went wrong.
File renamed without changes.
63 changes: 63 additions & 0 deletions
63
cardano-rosetta-server/src/server/utils/cardano/node/ogmios-client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* eslint-disable no-console */ | ||
/* eslint-disable no-magic-numbers */ | ||
/* eslint-disable no-useless-return */ | ||
import pRetry from 'p-retry'; | ||
import { | ||
ConnectionConfig, | ||
createConnectionObject, | ||
createInteractionContext, | ||
createStateQueryClient, | ||
createTxSubmissionClient, | ||
getServerHealth, | ||
ServerHealth, | ||
// Schema, | ||
StateQuery, | ||
TxSubmission | ||
} from '@cardano-ogmios/client'; | ||
import { Logger } from 'fastify'; | ||
|
||
const MODULE_NAME = 'OgmiosClient'; | ||
|
||
export interface OgmiosClient { | ||
submitTransaction(logger: Logger, transaction: string): Promise<void>; | ||
shutdown(): Promise<void>; | ||
} | ||
|
||
export const configure = async (ogmiosConnectionConfig?: ConnectionConfig): Promise<OgmiosClient> => { | ||
const serverHealthFetcher = await getServerHealth({ connection: createConnectionObject(ogmiosConnectionConfig) }); | ||
let txSubmissionClient: TxSubmission.TxSubmissionClient | undefined; | ||
await pRetry( | ||
async () => { | ||
txSubmissionClient = await createTxSubmissionClient( | ||
await createInteractionContext( | ||
error => { | ||
console.error({ module: MODULE_NAME, error: error.name }, error.message); | ||
}, | ||
console.info, | ||
{ | ||
connection: ogmiosConnectionConfig, | ||
interactionType: 'LongRunning' | ||
} | ||
) | ||
); | ||
}, | ||
{ | ||
factor: 1.2, | ||
retries: 100, | ||
onFailedAttempt: () => console.log('Establishing connection to cardano-node') | ||
} | ||
); | ||
return { | ||
submitTransaction: async (logger: Logger, transaction: string) => { | ||
if (serverHealthFetcher.networkSynchronization < 0.95) { | ||
throw new Error('Operation requires synced node'); | ||
} | ||
logger.info('[submitTransaction] About to submit transaction', transaction); | ||
await txSubmissionClient?.submitTx(transaction); | ||
logger.info('[submitTransaction] transaction successfully sent', transaction); | ||
}, | ||
shutdown: async () => { | ||
await txSubmissionClient?.shutdown(); | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.