Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
) => {
// tslint:disable-next-line: strict-type-predicates
if (storage !== undefined && init !== undefined) {
throw new Error(
'Storage and Init cannot be set a the same time. Please either use storage or init but not both.'
);
}
const contractCode = Array.isArray(code) ? code : ml2mic(code);
let contractStorage: object;
if (storage !== undefined) {
const schema = new Schema(contractCode[1].args[0]);
contractStorage = schema.Encode(storage);
} else {
contractStorage = typeof init === 'string' ? sexp2mic(init) : init;
}
const script = {
code: Array.isArray(code) ? code : ml2mic(code),
storage: contractStorage,
};
const operation: RPCOriginationOperation = {
kind: 'origination',
fee,
gas_limit: gasLimit,
storage_limit: storageLimit,
balance: format('tz', 'mutez', balance).toString(),
manager_pubkey: publicKeyHash,
spendable,
delegatable,
rawParam = false,
}: TransferParams) => {
const operation: RPCTransferOperation = {
kind: 'transaction',
fee,
gas_limit: gasLimit,
storage_limit: storageLimit,
amount: mutez ? amount.toString() : format('tz', 'mutez', amount).toString(),
destination: to,
};
if (parameter) {
operation.parameters = rawParam
? parameter
: typeof parameter === 'string'
? sexp2mic(parameter)
: parameter;
}
return operation;
};