vs-attestation-subscriber.js source code

const Web3 = require('web3');
const dotenv = require('dotenv');
dotenv.config();
const testNetWsUrl = process.env.WS;
const TruffleContract = require('truffle-contract');
const web3Provider = new Web3.providers.WebsocketProvider(testNetWsUrl);
const TrustAnchorStorageArtifact = require('./build/contracts/TrustAnchorStorage.json');
const TrustAnchorStorage = TruffleContract(TrustAnchorStorageArtifact);
TrustAnchorStorage.setProvider(web3Provider);
function setupTrustStorageManagerListeners() {
(async () => {
tas = await TrustAnchorStorage.deployed();
tas.EVT_setAttestation().on('data', (event) => {
console.log('EVT_setAttestation');
console.log(event);
trustAnchorGetAttestationComponents(event['returnValues']['attestationKeccak']);
}).on('error', function(error){
console.log(error);
});
console.log("setupTrustStorageManagerListeners EVT_setAttestation success");
})();
}
setupTrustStorageManagerListeners();
function trustAnchorGetAttestationComponents(attestation_hash) {
(async () => {
tas = await TrustAnchorStorage.deployed();
result = await tas.getAttestationComponents.call(attestation_hash)
console.log('getAttestationComponents result');
console.log(result);
})();
}