@okxweb3/coin-stellar
Version:
@ok/coin-stellar is a Stellar SDK for building Web3 wallets and applications. It supports Stellar and PI blockchains, enabling private key management, address generation, transaction signing, trustline creation, and asset transfers
35 lines • 1.38 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.manageData = void 0;
const xdr_1 = __importDefault(require("../xdr"));
function manageData(opts) {
const attributes = {};
if (!(typeof opts.name === 'string' && opts.name.length <= 64)) {
throw new Error('name must be a string, up to 64 characters');
}
attributes.dataName = opts.name;
if (typeof opts.value !== 'string' &&
!Buffer.isBuffer(opts.value) &&
opts.value !== null) {
throw new Error('value must be a string, Buffer or null');
}
if (typeof opts.value === 'string') {
attributes.dataValue = Buffer.from(opts.value);
}
else {
attributes.dataValue = opts.value;
}
if (attributes.dataValue !== null && attributes.dataValue.length > 64) {
throw new Error('value cannot be longer that 64 bytes');
}
const manageDataOp = new xdr_1.default.ManageDataOp(attributes);
const opAttributes = {};
opAttributes.body = xdr_1.default.OperationBody.manageData(manageDataOp);
this.setSourceAccount(opAttributes, opts);
return new xdr_1.default.Operation(opAttributes);
}
exports.manageData = manageData;
//# sourceMappingURL=manage_data.js.map