navio-blsct
Version:
TypeScript bindings for the `libblsct` library used by the [Navio](https://nav.io/) blockchain to construct confidential transactions based on the BLS12-381 curve.
95 lines (89 loc) • 3.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TxOut = void 0;
const blsct_1 = require("./blsct");
const managedObj_1 = require("./managedObj");
const subAddr_1 = require("./subAddr");
const tokenId_1 = require("./tokenId");
class TxOut extends managedObj_1.ManagedObj {
constructor(obj) {
super(obj);
}
static generate(subAddr, amount, memo, tokenId, outputType = blsct_1.TxOutputType.Normal, minStake = 0) {
tokenId = tokenId === undefined ?
tokenId_1.TokenId.default() : tokenId;
const rv = (0, blsct_1.buildTxOut)(subAddr.value(), amount, memo, tokenId.value(), outputType, minStake);
if (rv.result !== 0) {
(0, blsct_1.freeObj)(rv);
throw new Error(`Failed to build TxOut. Error code = ${rv.result}`);
}
const x = new TxOut(rv.value);
x.objSize = rv.value_size;
(0, blsct_1.freeObj)(rv);
return x;
}
value() {
return (0, blsct_1.castToTxOut)(this.obj);
}
getDestination() {
const obj = (0, blsct_1.getTxOutDestination)(this.value());
return subAddr_1.SubAddr.fromObj(obj);
}
getAmount() {
return (0, blsct_1.getTxOutAmount)(this.value());
}
getMemo() {
return (0, blsct_1.getTxOutMemo)(this.value());
}
getTokenId() {
const obj = (0, blsct_1.getTxOutTokenId)(this.value());
return tokenId_1.TokenId.fromObj(obj);
}
getOutputType() {
return (0, blsct_1.getTxOutOutputType)(this.value());
}
getMinStake() {
return (0, blsct_1.getTxOutMinStake)(this.value());
}
clone() {
const ser = this.serialize();
return TxOut.deserialize(ser);
}
serialize() {
const buf = (0, blsct_1.castToUint8_tPtr)(this.value());
return (0, blsct_1.toHex)(buf, this.size());
}
static deserialize(hex) {
if (hex.length % 2 !== 0) {
hex = `0${hex}`;
}
const obj = (0, blsct_1.hexToMallocedBuf)(hex);
const x = new TxOut(obj);
x.objSize = hex.length / 2;
return x;
}
}
exports.TxOut = TxOut;
/*
class TxOut(ManagedObj, Serializable):
def get_destination(self) -> SubAddr:
"""Get the destination of the transaction output."""
obj = blsct.get_tx_out_destination(self.value())
return SubAddr.from_obj(obj)
def get_amount(self) -> int:
"""Get the amount of the transaction output."""
return blsct.get_tx_out_amount(self.value())
def get_memo(self) -> str:
"""Get the memo of the transaction output."""
return blsct.get_tx_out_memo(self.value())
def get_token_id(self) -> TokenId:
"""Get the token ID of the transaction output."""
obj = blsct.get_tx_out_token_id(self.value())
return TokenId.from_obj(obj)
def get_output_type(self) -> TxOutputType:
"""Get the output type of the transaction output."""
return blsct.get_tx_out_output_type(self.value())
def get_min_stake(self) -> int:
"""Get the min stake of the transaction output."""
return blsct.get_tx_out_min_stake(self.value())
*/