diff --git a/packages/agent/chain.md b/packages/agent/chain.md index 3fa66da0bf..d21be862d4 100644 --- a/packages/agent/chain.md +++ b/packages/agent/chain.md @@ -233,30 +233,6 @@ Fetch all contracts that match one or more code IDs const result: Record<string, unknown> = await connection.fetchContractInfo(addresses: string) -## method [*connection.getCodeHashOfAddress*](https://github.com/hackbg/fadroma/tree/v2/packages/agent/chain.ts) -Get the code hash of a given address. -
-const result: string = await connection.getCodeHashOfAddress(contract: string | {
-  address,
-})
-
- -## method [*connection.getCodeHashOfCodeId*](https://github.com/hackbg/fadroma/tree/v2/packages/agent/chain.ts) -Get the code hash of a given code id. -
-const result: string = await connection.getCodeHashOfCodeId(contract: string | {
-  codeId,
-})
-
- -## method [*connection.getCodeId*](https://github.com/hackbg/fadroma/tree/v2/packages/agent/chain.ts) -Get the code id of a given address. -
-const result: string = await connection.getCodeId(contract: string | {
-  address,
-})
-
- ## method [*connection.getContract*](https://github.com/hackbg/fadroma/tree/v2/packages/agent/chain.ts) Get a client handle for a specific smart contract, authenticated as as this agent.
diff --git a/packages/agent/chain.ts b/packages/agent/chain.ts
index 308387acce..b0ab2e43dc 100644
--- a/packages/agent/chain.ts
+++ b/packages/agent/chain.ts
@@ -352,68 +352,63 @@ export abstract class Connection extends Endpoint {
     } else {
       throw new Error('fetchCodeInfo takes 0 or 1 arguments')
     }
+
+    //[>* Get the code hash of a given code id. <]
+    //getCodeHashOfCodeId (contract: Deploy.CodeId|{ codeId: Deploy.CodeId }): Promise {
+      //const codeId = (typeof contract === 'object') ? contract.codeId : contract
+      //this.log.debug(`Querying code hash of code id ${bold(codeId)}`)
+      //return timed(
+        //this.fetchCodeHashOfCodeIdImpl.bind(this, codeId),
+        //({ elapsed, result }) => this.log.debug(
+          //`Queried in ${bold(elapsed)}: code hash of code id ${bold(codeId)} is ${bold(result)}`
+        //)
+      //)
+    //}
   }
   /** Chain-specific implementation of fetchCodeInfo. */
   protected abstract fetchCodeInfoImpl (options: { ids?: Deploy.CodeId[] }|undefined):
     Promise>
-
-  /** Get the code id of a given address. */
-  getCodeId (contract: Address|{ address: Address }): Promise {
-    const address = (typeof contract === 'string') ? contract : contract.address
-    this.log.debug(`Querying code ID of ${bold(address)}`)
-    return timed(
-      this.fetchCodeIdImpl.bind(this, address),
-      ({ elapsed, result }) => this.log.debug(
-        `Queried in ${bold(elapsed)}: ${bold(address)} is code id ${bold(result)}`
-      )
-    )
-  }
-
   protected abstract fetchCodeIdImpl (contract: Address):
     Promise
-
-  /** Get the code hash of a given code id. */
-  getCodeHashOfCodeId (contract: Deploy.CodeId|{ codeId: Deploy.CodeId }): Promise {
-    const codeId = (typeof contract === 'object') ? contract.codeId : contract
-    this.log.debug(`Querying code hash of code id ${bold(codeId)}`)
-    return timed(
-      this.fetchCodeHashOfCodeIdImpl.bind(this, codeId),
-      ({ elapsed, result }) => this.log.debug(
-        `Queried in ${bold(elapsed)}: code hash of code id ${bold(codeId)} is ${bold(result)}`
-      )
-    )
-  }
-
   protected abstract fetchCodeHashOfCodeIdImpl (codeId: Deploy.CodeId):
     Promise
 
   /////////////////////////////////////////////////////////////////////////////////////////////////
 
-  fetchContractInfo (address: Address): Promise
-  fetchContractInfo (addresses: Address[]): Promise>
+  fetchContractInfo (address: Address):
+    Promise
+  fetchContractInfo (addresses: Address[]):
+    Promise>
   async fetchContractInfo (...args: unknown[]): Promise {
     throw new Error("unimplemented!")
     return {}
+    //getCodeHashOfAddress (contract: Address|{ address: Address }): Promise {
+      //const address = (typeof contract === 'string') ? contract : contract.address
+      //this.log.debug(`Querying code hash of address ${bold(address)}`)
+      //return timed(
+        //this.fetchCodeHashOfAddressImpl.bind( this, address),
+        //({ elapsed, result }) => this.log.debug(
+          //`Queried in ${bold(elapsed)}: code hash of address ${bold(address)} is ${bold(result)}`
+        //)
+      //)
+    //}
+    /** Get the code id of a given address. */
+    //getCodeId (contract: Address|{ address: Address }): Promise {
+      //const address = (typeof contract === 'string') ? contract : contract.address
+      //this.log.debug(`Querying code ID of ${bold(address)}`)
+      //return timed(
+        //this.fetchCodeIdImpl.bind(this, address),
+        //({ elapsed, result }) => this.log.debug(
+          //`Queried in ${bold(elapsed)}: ${bold(address)} is code id ${bold(result)}`
+        //)
+      //)
+    //}
   }
   /** Chain-specific implementation of fetchContractInfo. */
   protected abstract fetchContractInfoImpl (): Promise
-  /** Get the code hash of a given address. */
-  getCodeHashOfAddress (contract: Address|{ address: Address }): Promise {
-    const address = (typeof contract === 'string') ? contract : contract.address
-    this.log.debug(`Querying code hash of address ${bold(address)}`)
-    return timed(
-      this.fetchCodeHashOfAddressImpl.bind( this, address),
-      ({ elapsed, result }) => this.log.debug(
-        `Queried in ${bold(elapsed)}: code hash of address ${bold(address)} is ${bold(result)}`
-      )
-    )
-  }
-  protected abstract fetchCodeHashOfAddressImpl (
-    contract: Address
-  ): Promise
   /** Get a client handle for a specific smart contract, authenticated as as this agent. */
-  getContract (
-    options: Address|{ address: Address }): Contract
+  getContract (options: Address|{ address: Address }):
+    Contract
   getContract  (
     options: Address|{ address: Address }, $C: C = Contract as C,
   ): InstanceType {
diff --git a/packages/agent/stub.md b/packages/agent/stub.md
index 6b02e669dc..9148936b5f 100644
--- a/packages/agent/stub.md
+++ b/packages/agent/stub.md
@@ -216,30 +216,6 @@ Fetch all contracts that match one or more code IDs
 const result: Record<string, unknown> = await stubConnection.fetchContractInfo(addresses: string)
 
-## method [*stubConnection.getCodeHashOfAddress*](https://github.com/hackbg/fadroma/tree/v2/packages/agent/chain.ts) -Get the code hash of a given address. -
-const result: string = await stubConnection.getCodeHashOfAddress(contract: string | {
-  address,
-})
-
- -## method [*stubConnection.getCodeHashOfCodeId*](https://github.com/hackbg/fadroma/tree/v2/packages/agent/chain.ts) -Get the code hash of a given code id. -
-const result: string = await stubConnection.getCodeHashOfCodeId(contract: string | {
-  codeId,
-})
-
- -## method [*stubConnection.getCodeId*](https://github.com/hackbg/fadroma/tree/v2/packages/agent/chain.ts) -Get the code id of a given address. -
-const result: string = await stubConnection.getCodeId(contract: string | {
-  address,
-})
-
- ## method [*stubConnection.getContract*](https://github.com/hackbg/fadroma/tree/v2/packages/agent/chain.ts) Get a client handle for a specific smart contract, authenticated as as this agent.
diff --git a/packages/agent/stub.ts b/packages/agent/stub.ts
index d025108db9..89503a11e9 100644
--- a/packages/agent/stub.ts
+++ b/packages/agent/stub.ts
@@ -54,20 +54,21 @@ export class StubConnection extends Connection {
     const balance = (this.backend.balances.get(address!)||{})[token] ?? 0
     return Promise.resolve(String(balance))
   }
-  protected async getCodeIdImpl (address: Address): Promise {
-    const contract = this.backend.instances.get(address)
-    if (!contract) {
-      throw new Error(`unknown contract ${address}`)
-    }
-    return contract.codeId
-  }
   protected fetchContractsByCodeIdImpl (id: CodeId) {
     return Promise.resolve([...this.backend.uploads.get(id)!.instances]
       .map(address=>({address})))
   }
   protected fetchCodeHashOfAddressImpl (address: Address): Promise {
-    return this.getCodeId(address)
-      .then(id=>this.getCodeHashOfCodeId(id))
+    const contract = this.backend.instances.get(address)
+    if (!contract) {
+      throw new Error(`unknown contract ${address}`)
+    }
+    const { codeId } = contract
+    const code = this.backend.uploads.get(codeId)
+    if (!code) {
+      throw new Error(`inconsistent state: missing code ${codeId} for address ${address}`)
+    }
+    return Promise.resolve(code.codeHash)
   }
   protected fetchCodeHashOfCodeIdImpl (id: CodeId): Promise {
     const code = this.backend.uploads.get(id)