input-output-hk/cardano-js-sdk

cardano-graphql Provider

rhyslbw opened this issue · 0 comments

1. Hoist the Provider to the core package

The prototype modelled the concept of remote wallets, and required the Provider to be typed as either Cardano or Wallet. We have de-scoped this to focus exclusively on client-side wallets, so the concept can be reduced to what is observed here:

export interface CardanoProvider extends BaseProvider {
submitTransaction: SubmitTransaction
queryUtxosByAddress: QueryUtxosByAddress
queryTransactionsByAddress: QueryTransactionsByAddress
queryTransactionsById: QueryTransactionsById
}

Align the Provider interface with the API defined by Ogmios, as this is a reflection of the Cardano model. i.e :

  • submitTransaction -> submitTx
  • queryUtxosByAddress -> utxo

Replace the types defined here with what can be imported by the @cardano-ogmios/client package:

export type SubmitTransaction = (signedTransaction: string) => Promise<boolean>
export type QueryUtxosByAddress = (addresses: string[]) => Promise<Utxo[]>
export type QueryTransactionsByAddress = (addresses: string[]) => Promise<{ id: string, inputs: TransactionInput[], outputs: TransactionOutput[] }[]>
export type QueryTransactionsById = (ids: string[]) => Promise<any[]>

We will add other methods in later tasks.

2. Create a new package called @cardano-sdk/cardano-graphql-provider

Create an implementation of the provider using @cardano-graphql/client-ts.
Here's a sample from the prototype:

import { CardanoProvider } from '../../Provider'
export function ClientHttpProvider (_uri: string): CardanoProvider {
// To be implemented by: https://github.com/input-output-hk/cardano-js-sdk/issues/4
// This will likely convert this interface to interact with Jormangandr and remove the any
// type casting
return {
submitTransaction: (_signedTransaction: string) => new Error('Not yet implemented'),
queryUtxo: (_utxos: string[]) => new Error('Not yet implemented')
} as any
}

Use the public testnet for basic tests where applicable, selecting a random address using the explorer. It's acceptable to defer tests for the submitTx until we have covered this feature.