Attaching to tangle

This commit is contained in:
Martyn Janes
2019-12-19 14:06:27 +01:00
parent 5b147bfb58
commit 8b5dba603f
4 changed files with 22814 additions and 250 deletions

23004
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -23,6 +23,7 @@
"@actions/core": "^1.2.0",
"@actions/exec": "^1.0.2",
"@actions/github": "^2.0.0",
"@iota/converter": "^1.0.0-beta.23",
"@iota/core": "^1.0.0-beta.24",
"axios": "^0.19.0"
},

View File

@@ -1,12 +1,46 @@
const { composeAPI, generateAddress } = require('@iota/core');
const { asciiToTrytes } = require('@iota/converter');
function encodeNonASCII(value) {
return value
? value.replace(/[\u007F-\uFFFF]/g, chr => `\\u${`0000${chr.charCodeAt(0).toString(16)}`.substr(-4)}`)
: undefined;
}
/* eslint-disable no-console */
async function attachToTangle(provider, depth, mwm, seed, addressIndex, payload) {
async function attachToTangle(provider, depth, mwm, seed, addressIndex, tag, payload) {
console.log('provider', provider);
console.log('depth', depth);
console.log('mwm', mwm);
console.log('seed', seed);
console.log('addressIndex', addressIndex);
console.log('payload', payload);
return 'A'.repeat(81);
const json = JSON.stringify(payload);
console.log(json);
const ascii = encodeNonASCII(json);
console.log(ascii);
const message = asciiToTrytes(ascii);
console.log(message);
const iota = composeAPI({
provider
});
const address = generateAddress(seed, addressIndex);
const trytes = await iota.prepareTransfers('9'.repeat(81), [
{
address,
value: 0,
message,
tag
}
]);
const bundles = await iota.sendTrytes(trytes, depth, mwm);
return bundles[0].hash;
}
module.exports = {

View File

@@ -9,23 +9,32 @@ async function run() {
const github = new GitHub(process.env.GITHUB_TOKEN);
const seed = process.env.IOTA_SEED;
const tag = process.env.IOTA_TAG || 'GITHUB9RELEASE';
let provider = process.env.IOTA_PROVIDER;
let addressIndex = process.env.IOTA_ADDRESS_INDEX;
const depth = process.env.IOTA_DEPTH || 3;
const mwm = process.env.IOTA_MWM || 14;
let addressIndex = parseInt(process.env.IOTA_ADDRESS_INDEX, 10);
let depth = parseInt(process.env.IOTA_DEPTH, 10);
let mwm = parseInt(process.env.IOTA_MWM, 10);
if (!seed) {
throw new Error('You must provider the IOTA_SEED env variable');
throw new Error('You must provide the IOTA_SEED env variable');
}
if (!provider || provider.length === 0) {
provider = 'https://nodes.iota.cafe:443';
}
if (addressIndex === undefined || addressIndex === null) {
if (Number.isNaN(addressIndex)) {
addressIndex = 0;
}
if (Number.isNaN(mwm)) {
mwm = 14;
}
if (Number.isNaN(depth)) {
depth = 3;
}
const { owner, repo } = context.repo;
const tagName = core.getInput('tag_name', { required: true });
@@ -67,7 +76,7 @@ async function run() {
}
}
const txHash = await attachToTangle(provider, depth, mwm, seed, addressIndex, payload);
const txHash = await attachToTangle(provider, depth, mwm, seed, addressIndex, tag, payload);
core.setOutput('tx_hash', txHash);
} catch (error) {
core.setFailed(error.message);