This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shim from 'fabric-shim'; | |
import util from 'util'; | |
export default class Chaincode { | |
// 1. Mandatory Init function | |
async Init(stub) { | |
const ret = stub.getFunctionAndParameters(); | |
console.info(ret); | |
console.info('=========== Instantiated Codigo Rastreamento Chaincode ==========='); | |
return shim.success(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "codigo-rastreamento", | |
"version": "1.0.0", | |
"description": "Codigo Rastreamento chaincode implemented in node.js", | |
"engines": { | |
"node": ">=8.4.0", | |
"npm": ">=5.3.0" | |
}, | |
"scripts": { | |
"clean": "rm -rf build && mkdir build", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [..] | |
// 2. Mandatory Invoke function | |
async Invoke(stub) { | |
console.info('########################################'); | |
console.info(`Transaction ID: ${stub.getTxID()}`); | |
console.info(util.format('Args: %j', stub.getArgs())); | |
const ret = stub.getFunctionAndParameters(); | |
console.info(ret); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [..] | |
// Function for retrieving state value | |
async getDataById(stub, args) { | |
// Assigns id to data | |
const data = args[0]; | |
// Verifies id is not empty | |
if (!data) { | |
throw new Error('Por favor especifique um id'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"presets": [ | |
"es2015" | |
], | |
"plugins": ["transform-object-rest-spread"] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shim from 'fabric-shim'; | |
import util from 'util'; | |
import * as Codigo from './controllers/codigo'; | |
export default class Chaincode { | |
// [...] | |
// Function for creating batch of tracking code | |
async solicitarCodigo(stub, args) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import uuidv4 from 'uuid/v4'; | |
// import { performance } from 'perf_hooks'; | |
import { generateCodigo } from '../utils'; | |
export const solicitarCodigo = async (stub, args) => { | |
// const t0 = performance.now(); | |
let data; | |
const codigoPutStatePromises = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [...] | |
async usarCodigo(stub, args) { | |
try { | |
await Codigo.usarCodigo(stub, args); | |
} catch (err) { | |
throw new Error(err.message ? err.message : 'Por favor tente novamente mais tarde'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import uuidv4 from 'uuid/v4'; | |
// import { performance } from 'perf_hooks'; | |
import { generateCodigo } from '../utils'; | |
import { usarCodigoSchema } from '../models/codigo'; | |
// { descend into nested schema, return on first error, remove unspecified keys from objects } | |
const validationOptions = { recursive: true, abortEarly: true, stripUnknown: true }; | |
// [...] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const yup = require('yup'); | |
/* eslint-disable import/prefer-default-export */ | |
export const usarCodigoSchema = yup.object().shape({ | |
id: yup.string().required('Por favor especifique um id'), | |
transportador: yup.string().required('Por favor especifique um transportador'), | |
rota: yup.string().required('Por favor especifique uma rota'), | |
servico: yup.string().required('Por favor especifique um servico'), | |
servico_codigo: yup.string().required('Por favor especifique um servico_codigo'), | |
usado: yup |
OlderNewer