mirror of
https://github.com/tauri-apps/gh-tangle-release.git
synced 2026-02-04 02:31:18 +01:00
Attaching to tangle
This commit is contained in:
23004
dist/index.js
vendored
23004
dist/index.js
vendored
File diff suppressed because one or more lines are too long
@@ -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"
|
||||
},
|
||||
|
||||
38
src/iota.js
38
src/iota.js
@@ -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 = {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user