diff --git a/app.js b/app.js index 47b8fb372..32b4420f6 100644 --- a/app.js +++ b/app.js @@ -270,7 +270,7 @@ function build_marble_options(username, company){ var sizes = ['35', '16']; var color_index = simple_hash(more_entropy + company) % colors.length; //build a psudeo random index to pick a color var size_index = getRandomInt(0, sizes.length); //build a random size for this marble - return [randStr(24), colors[color_index], sizes[size_index], username, company]; + return [randStr(24), colors[color_index], sizes[size_index], username, company, process.env.marble_company]; } //this only runs after we deploy diff --git a/chaincode/lib_marbles.go b/chaincode/lib_marbles.go index 0fe3bfddc..49d564d76 100644 --- a/chaincode/lib_marbles.go +++ b/chaincode/lib_marbles.go @@ -146,10 +146,10 @@ func init_marble(stub shim.ChaincodeStubInterface, args []string) ([]byte, error var err error fmt.Println("starting init_marble") - // 0 1 2 3 4 - // "asdf", "blue", "35", "bob", "united marbles" - if len(args) != 5 { - return nil, errors.New("Incorrect number of arguments. Expecting 5") + // 0 1 2 3 4 5 + // "asdf", "blue", "35", "bob", "united marbles", "united marbles" + if len(args) != 6 { + return nil, errors.New("Incorrect number of arguments. Expecting 6") } //input sanitation @@ -172,11 +172,17 @@ func init_marble(stub shim.ChaincodeStubInterface, args []string) ([]byte, error color := strings.ToLower(args[1]) username := strings.ToLower(args[3]) company := args[4] + authed_by_company := args[5] size, err := strconv.Atoi(args[2]) if err != nil { return nil, errors.New("3rd argument must be a numeric string") } + //check authorizing company + if company != authed_by_company{ + return nil, errors.New("The company '" + authed_by_company + "' cannot authorize deletion for '" + company + "'.") + } + //check if marble already exists marble, err := get_marble(stub, name) if err == nil { diff --git a/utils/marbles_cc_lib/marbles.js b/utils/marbles_cc_lib/marbles.js index 5500a64de..d967b28d4 100644 --- a/utils/marbles_cc_lib/marbles.js +++ b/utils/marbles_cc_lib/marbles.js @@ -32,6 +32,7 @@ module.exports = function (chain, chaincode_id, logger) { } else { console.log('Failed to obtain transaction endorsement'); + if(ws) ws.send(JSON.stringify({msg: 'tx_step', state: 'endorsing_failed'})); throw common.format_error_msg(proposalResponses[0]); } } @@ -44,6 +45,7 @@ module.exports = function (chain, chaincode_id, logger) { } else { console.log('Failed to order the endorsement of the transaction.'); + if(ws) ws.send(JSON.stringify({msg: 'tx_step', state: 'ordering_failed'})); throw response; } } @@ -55,6 +57,7 @@ module.exports = function (chain, chaincode_id, logger) { e = err; } if(typeof err === 'string'){ //only pass these errors until we fix it + if(err.indexOf('cannot authorize')) e = err; if(err.indexOf('marble already exists')) e = err; if(err.indexOf('Incorrect number of arguments')) e = err; if(err.indexOf('argument must be')) e = err; diff --git a/utils/websocket_server_side.js b/utils/websocket_server_side.js index bd82514e0..5999dc890 100644 --- a/utils/websocket_server_side.js +++ b/utils/websocket_server_side.js @@ -33,7 +33,7 @@ module.exports = function (checkPerodically, marbles_lib, logger) { // create a new marble if(data.type == 'create'){ console.log('[ws] create marbles req'); - options = [data.name, data.color, data.size, data.username, data.company]; + options = [data.name, data.color, data.size, data.username, data.company, process.env.marble_company]; marbles_lib.create_a_marble(webUser, [hfc.getPeer(helper.getPeersUrl(0))], ws, options, function(err, resp){ if(err != null) send_err(err, data); }); @@ -203,8 +203,10 @@ module.exports = function (checkPerodically, marbles_lib, logger) { } else{ var data = resp.payload[0]; - console.log('\n\n[checking] number of owners:', data.owners_index.length); - console.log('[checking] number of marbles:', data.marbles.length, '\n\n'); + if(data && data.owners && data.marbles && data.owners_index){ + console.log('\n\n[checking] number of owners:', data.owners_index.length); + console.log('[checking] number of marbles:', data.marbles.length, '\n\n'); + } data.owners_index = organize_usernames(data.owners_index); data.marbles = organize_marbles(data.marbles);