Searching in the existing folders I ended up finding the UPLCEncoder
implementation.
in particular, the class exposes a compile method
that has the following signature:
compile( program: UPLCProgram ): BitStream
so it is something that given a UPLCProgram
instance returns a BitStream
; the implementation of the BitStream
class suggest it is a wrapper ona bigint
js primitive value used to store the compiled program.
back to the compile
method; the library already supports hoisting; so the first part of the method is about inlining hoisted terms;
the actual compilation is forwarded to the encodeTerm
method as we can see from
result.append(
this.encodeTerm(
progrTerm
)
);
the implementation of encodeTerm
is just an intermediate step to choose the encoding to use based on the actual UPLCTerm
instance passed.
once encodeTerm
understands the type of the terms calls the specific encoding function that translates 1:1 the UPLCTerm
to binary (using BitStream
) and calls again encodeTerm
(mutually recursive) when necessary as in the case of Application
encoding
const result = Application.UPLCTag;
this._ctx.incrementLengthBy( result.length );
result.append(
this.encodeTerm( app.funcTerm )
);
result.append(
this.encodeTerm( app.argTerm )
);
once compile
returns the BitStream
currently the solution is to use the toBuffer
method to get a Buffer
from it and convert it to the serialized hexadecimal string that can be submitted in a transaction, just like any other smart contract.
it has to be said that the project is quite new so I'm sure there will be a more direct way to obtain the hexadecimal string.