Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function modifyTransactionForEmptyTransaction<
U extends tx.BaseTransaction,
T extends ManagedApiBasicConfig<u>
>(config: T): Promise {
if (config.tx!.inputs.length === 0 && config.tx!.outputs.length === 0) {
config.tx!.addAttribute(
tx.TxAttrUsage.Script,
u.reverseHex(wallet.getScriptHashFromAddress(config.account!.address))
);
// This adds some random bits to the transaction to prevent any hash collision.
config.tx!.addRemark(
Date.now().toString() + u.ab2hexstring(u.generateRandomArray(4))
);
}
return config;
}
</u>
test("add attribute if sendingFromSmartContract", async () => {
const config = {
account: {
scriptHash: "abcd"
},
sendingFromSmartContract: "5b7074e873973a6ed3708862f219a6fbf4d1c411",
tx: { addAttribute: jest.fn() }
} as any;
const result = await smartcontract.addAttributeIfExecutingAsSmartContract(
config
);
expect(config.tx.addAttribute).toBeCalledWith(
tx.TxAttrUsage.Script,
"11c4d1f4fba619f2628870d36e3a9773e874705b"
);
});
});
}
}
} else {
if (this.fee > 0) {
try {
newTx = await this.addFee(this.neon.wallet.accounts[0].address, newTx, this.fee);
} catch (error) {
console.log(error);
}
}
}
} else {
newTx.outputs = this.assetIntentOverrides.outlets;
newTx.inputs = this.assetIntentOverrides.inputs;
}
newTx.addAttribute(tx.TxAttrUsage.Script, u.reverseHex(fromScript));
const uniqTag = `from NEOLine at ${new Date().getTime()}`;
newTx.addAttribute(tx.TxAttrUsage.Remark1, u.reverseHex(u.str2hexstring(uniqTag)));
resolve(newTx);
});
}
import { CONST, tx, u } from "@cityofzion/neon-core";
const requiresProcessing = [
tx.TxAttrUsage.Description,
tx.TxAttrUsage.DescriptionUrl,
tx.TxAttrUsage.Remark,
tx.TxAttrUsage.Remark2,
tx.TxAttrUsage.Remark3,
tx.TxAttrUsage.Remark4,
tx.TxAttrUsage.Remark5,
tx.TxAttrUsage.Remark6,
tx.TxAttrUsage.Remark7,
tx.TxAttrUsage.Remark8,
tx.TxAttrUsage.Remark9,
tx.TxAttrUsage.Remark10,
tx.TxAttrUsage.Remark11,
tx.TxAttrUsage.Remark12,
tx.TxAttrUsage.Remark13,
tx.TxAttrUsage.Remark14,
tx.TxAttrUsage.Remark15
import { CONST, tx, u } from "@cityofzion/neon-core";
const requiresProcessing = [
tx.TxAttrUsage.Description,
tx.TxAttrUsage.DescriptionUrl,
tx.TxAttrUsage.Remark,
tx.TxAttrUsage.Remark2,
tx.TxAttrUsage.Remark3,
tx.TxAttrUsage.Remark4,
tx.TxAttrUsage.Remark5,
tx.TxAttrUsage.Remark6,
tx.TxAttrUsage.Remark7,
tx.TxAttrUsage.Remark8,
tx.TxAttrUsage.Remark9,
tx.TxAttrUsage.Remark10,
tx.TxAttrUsage.Remark11,
tx.TxAttrUsage.Remark12,
tx.TxAttrUsage.Remark13,
tx.TxAttrUsage.Remark14,
tx.TxAttrUsage.Remark15
];
export function extractAsset(params: {
[key: string]: string;
}): string | undefined {
if (!params.asset) {
return undefined;
}
switch (params.asset) {
case "neo":
return CONST.ASSET_ID.NEO;
export async function addAttributeIfExecutingAsSmartContract<
T extends ManagedApiBasicConfig
>(config: T): Promise {
if (!config.sendingFromSmartContract) {
return config;
}
config.tx!.addAttribute(
tx.TxAttrUsage.Script,
u.reverseHex(config.sendingFromSmartContract)
);
return config;
}
export async function addAttributeForMintToken(
config: DoInvokeConfig
): Promise {
if (
typeof config.script === "object" &&
config.script.operation === "mintTokens" &&
config.script.scriptHash
) {
config.tx!.addAttribute(
tx.TxAttrUsage.Script,
u.reverseHex(config.script.scriptHash)
);
}
return config;
}