@@ -7,7 +7,13 @@ import {
77 type ClientBlockHeaderLike ,
88} from "../client/index.js" ;
99import { KnownScript } from "../client/knownScript.js" ;
10- import { Codec , Entity , codec } from "../codec/index.js" ;
10+ import {
11+ Codec ,
12+ Encodable ,
13+ Entity ,
14+ codec ,
15+ encodableToHex ,
16+ } from "../codec/index.js" ;
1117import { Zero , fixedPointFrom } from "../fixedPoint/index.js" ;
1218import { Hasher , HasherCkb , hashCkb } from "../hasher/index.js" ;
1319import { Hex , HexLike , hexFrom } from "../hex/index.js" ;
@@ -121,7 +127,7 @@ export function depTypeFromBytes(bytes: BytesLike): DepType {
121127 * @public
122128 */
123129export type OutPointLike = {
124- txHash : HexLike ;
130+ txHash : Encodable ;
125131 index : NumLike ;
126132} ;
127133/**
@@ -163,7 +169,10 @@ export class OutPoint extends Entity.Base<OutPointLike, OutPoint>() {
163169 if ( outPoint instanceof OutPoint ) {
164170 return outPoint ;
165171 }
166- return new OutPoint ( hexFrom ( outPoint . txHash ) , numFrom ( outPoint . index ) ) ;
172+ return new OutPoint (
173+ encodableToHex ( outPoint . txHash ) ,
174+ numFrom ( outPoint . index ) ,
175+ ) ;
167176 }
168177
169178 /**
@@ -263,7 +272,7 @@ export class CellOutput extends Entity.Base<CellOutputLike, CellOutput>() {
263272 */
264273 static from (
265274 cellOutput : CellOutputLike ,
266- outputData ?: HexLike | null ,
275+ outputData ?: Encodable | null ,
267276 ) : CellOutput {
268277 const output = ( ( ) => {
269278 if ( cellOutput instanceof CellOutput ) {
@@ -279,7 +288,9 @@ export class CellOutput extends Entity.Base<CellOutputLike, CellOutput>() {
279288 if ( outputData != null ) {
280289 output . capacity = numMax (
281290 output . capacity ,
282- fixedPointFrom ( output . occupiedSize + bytesFrom ( outputData ) . length ) ,
291+ fixedPointFrom (
292+ output . occupiedSize + encodableToBytes ( outputData ) . length ,
293+ ) ,
283294 ) ;
284295 }
285296
@@ -783,7 +794,7 @@ export type CellInputLike = (
783794) & {
784795 since ?: SinceLike | NumLike | null ;
785796 cellOutput ?: CellOutputLike | null ;
786- outputData ?: HexLike | null ;
797+ outputData ?: Encodable | null ;
787798} ;
788799/**
789800 * @public
@@ -840,10 +851,11 @@ export class CellInput extends Entity.Base<CellInputLike, CellInput>() {
840851 ? cellInput . previousOutput
841852 : cellInput . outPoint ,
842853 ) ,
843- Since . from ( cellInput . since ?? 0 ) . toNum ( ) ,
854+ numFrom ( cellInput . since ?? 0 ) ,
844855 apply ( CellOutput . from , cellInput . cellOutput ) ,
845- apply ( hexFrom , cellInput . outputData ) ,
856+ apply ( encodableToHex , cellInput . outputData ) ,
846857 ) ;
858+
847859 }
848860
849861 async getCell ( client : Client ) : Promise < Cell > {
@@ -992,9 +1004,9 @@ export const CellDepVec = mol.vector(CellDep);
9921004 * @public
9931005 */
9941006export type WitnessArgsLike = {
995- lock ?: HexLike | null ;
996- inputType ?: HexLike | null ;
997- outputType ?: HexLike | null ;
1007+ lock ?: Encodable | null ;
1008+ inputType ?: Encodable | null ;
1009+ outputType ?: Encodable | null ;
9981010} ;
9991011/**
10001012 * @public
@@ -1045,9 +1057,9 @@ export class WitnessArgs extends Entity.Base<WitnessArgsLike, WitnessArgs>() {
10451057 }
10461058
10471059 return new WitnessArgs (
1048- apply ( hexFrom , witnessArgs . lock ) ,
1049- apply ( hexFrom , witnessArgs . inputType ) ,
1050- apply ( hexFrom , witnessArgs . outputType ) ,
1060+ apply ( encodableToHex , witnessArgs . lock ) ,
1061+ apply ( encodableToHex , witnessArgs . inputType ) ,
1062+ apply ( encodableToHex , witnessArgs . outputType ) ,
10511063 ) ;
10521064 }
10531065}
@@ -1083,8 +1095,8 @@ export type TransactionLike = {
10831095 | ( Omit < CellOutputLike , "capacity" > &
10841096 Partial < Pick < CellOutputLike , "capacity" > > ) [ ]
10851097 | null ;
1086- outputsData ?: HexLike [ ] | null ;
1087- witnesses ?: HexLike [ ] | null ;
1098+ outputsData ?: Encodable [ ] | null ;
1099+ witnesses ?: Encodable [ ] | null ;
10881100} ;
10891101/**
10901102 * @public
@@ -1243,11 +1255,13 @@ export class Transaction extends Entity.Base<TransactionLike, Transaction>() {
12431255 CellOutput . from ( output , tx . outputsData ?. [ i ] ?? [ ] ) ,
12441256 ) ?? [ ] ;
12451257 const outputsData = outputs . map ( ( _ , i ) =>
1246- hexFrom ( tx . outputsData ?. [ i ] ?? "0x" ) ,
1258+ encodableToHex ( tx . outputsData ?. [ i ] ?? "0x" ) ,
12471259 ) ;
12481260 if ( tx . outputsData != null && outputsData . length < tx . outputsData . length ) {
12491261 outputsData . push (
1250- ...tx . outputsData . slice ( outputsData . length ) . map ( ( d ) => hexFrom ( d ) ) ,
1262+ ...tx . outputsData
1263+ . slice ( outputsData . length )
1264+ . map ( ( d ) => encodableToHex ( d ) ) ,
12511265 ) ;
12521266 }
12531267
@@ -1258,7 +1272,7 @@ export class Transaction extends Entity.Base<TransactionLike, Transaction>() {
12581272 tx . inputs ?. map ( ( input ) => CellInput . from ( input ) ) ?? [ ] ,
12591273 outputs ,
12601274 outputsData ,
1261- tx . witnesses ?. map ( hexFrom ) ?? [ ] ,
1275+ tx . witnesses ?. map ( encodableToHex ) ?? [ ] ,
12621276 ) ;
12631277 }
12641278
@@ -1808,8 +1822,8 @@ export class Transaction extends Entity.Base<TransactionLike, Transaction>() {
18081822 * await tx.setWitnessArgsAt(0, witnessArgs);
18091823 * ```
18101824 */
1811- setWitnessArgsAt ( index : number , witness : WitnessArgs ) : void {
1812- this . setWitnessAt ( index , witness . toBytes ( ) ) ;
1825+ setWitnessArgsAt ( index : number , witness : WitnessArgsLike ) : void {
1826+ this . setWitnessAt ( index , WitnessArgs . from ( witness ) . toBytes ( ) ) ;
18131827 }
18141828
18151829 /**
0 commit comments