Skip to content

Commit

Permalink
Merge pull request #11 from unipackage/feat/add-gettxhash-method
Browse files Browse the repository at this point in the history
feat: 🎸 add EthGetTransactionHashByCid to ChainFilecoinRPC
  • Loading branch information
lovel8 authored Mar 22, 2024
2 parents 8335022 + c0472c8 commit 6eb9aa1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/chain/repo/rpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ interface ChainFilecoinOriginRPC {
): Promise<RPCResponse<Tipset>>
ChainGetBlockMessages(...params: any[]): Promise<RPCResponse<BlockMessages>>
StateReplay(...params: any[]): Promise<RPCResponse<Message>>
EthGetTransactionHashByCid(cid: CidProperty): Promise<RPCResponse<string>>
}

/**
Expand All @@ -49,6 +50,7 @@ interface ChainFilecoinOriginRPC {
"ChainGetTipSetByHeight",
"ChainGetBlockMessages",
"StateReplay",
"EthGetTransactionHashByCid",
])
class ChainFilecoinOriginRPC extends FilecoinRPCEngine {}

Expand Down Expand Up @@ -131,4 +133,19 @@ export class ChainFilecoinRPC extends ChainFilecoinOriginRPC {
}
return res
}

/**
* Retrieves the Ethereum transaction hash by CID (Content Identifier).
* @param cid The CID (Content Identifier) property.
* @returns {Promise<RPCResponse<string>>} A Promise resolving to RPCResponse containing the Ethereum transaction hash.
*/
public async EthGetTransactionHashByCid(
cid: CidProperty
): Promise<RPCResponse<string>> {
const res: any = await super.EthGetTransactionHashByCid(cid)
if (res.ok && res.data) {
res.data = String(res.data)
}
return res
}
}
13 changes: 13 additions & 0 deletions test/chain/repo/rpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { expect } from "chai"
import { Tipset } from "../../../src/basic/tipset/types"
import { Message } from "../../../src/basic/message/types"
import { BlockMessages } from "../../../src/basic/block/types"
import { Cid, CidProperty } from "../../../src/basic/cid/types"
dotenv.config()

describe("RPC", () => {
Expand Down Expand Up @@ -91,4 +92,16 @@ describe("RPC", () => {
}
})
})
describe.skip("EthGetTransactionHashByCid", () => {
it("should ok", async function (this: Context) {
this.timeout(10000)
const res = await rpc.EthGetTransactionHashByCid({
"/": "bafy2bzacebwksgenvlvw2bwylwmrnprvqenlmdzpylb63iso6jsygi2sbxolg",
} as CidProperty)
expect(res.ok).to.be.equal(true)
expect(res.data).to.be.equal(
"0xc24902d9e3f96872d70b551ff73b8fa22b5e59e922eaf944b64f6cab8a388bf1"
)
})
})
})

0 comments on commit 6eb9aa1

Please sign in to comment.