Fixed comment consistency problem (#844)

* fixed comment consistency problem with erc20 chaincode

Signed-off-by: Ali Shahverdi <ali@Alis-MacBook-Pro.local>

* added more comment consistancy fix

Signed-off-by: Ali Shahverdi <ali@Alis-MacBook-Pro.local>

* added more comment consistancy fix

Signed-off-by: Ali Shahverdi <ali@Alis-MacBook-Pro.local>

* added more comment consistancy fix

Signed-off-by: Ali Shahverdi <ali@Alis-MacBook-Pro.local>

* added more comment consistancy fix

Signed-off-by: Ali Shahverdi <ali@Alis-MacBook-Pro.local>

Signed-off-by: Ali Shahverdi <ali@Alis-MacBook-Pro.local>
Co-authored-by: Ali Shahverdi <ali@Alis-MacBook-Pro.local>
This commit is contained in:
ali 2022-12-14 11:48:21 +03:30 committed by GitHub
parent b2de360e1c
commit 05c06f4931
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
41 changed files with 190 additions and 191 deletions

View file

@ -28,7 +28,7 @@ func (s *SmartContract) CreateAsset(ctx contractapi.TransactionContextInterface,
// Demonstrate the use of Attribute-Based Access Control (ABAC) by checking
// to see if the caller has the "abac.creator" attribute with a value of true;
// if not, return an error.
//
err := ctx.GetClientIdentity().AssertAttributeValue("abac.creator", "true")
if err != nil {
return fmt.Errorf("submitting client not authorized to create asset, does not have abac.creator role")

View file

@ -64,7 +64,7 @@ public class App {
System.out.println("\n");
System.out.println("Submit Transaction: CreateAsset asset13");
//CreateAsset creates an asset with ID asset13, color yellow, owner Tom, size 5 and appraisedValue of 1300
// CreateAsset creates an asset with ID asset13, color yellow, owner Tom, size 5 and appraisedValue of 1300
contract.submitTransaction("CreateAsset", "asset13", "yellow", "5", "Tom", "1300");
System.out.println("\n");
@ -92,7 +92,7 @@ public class App {
try {
System.out.println("\n");
System.out.println("Submit Transaction: UpdateAsset asset70");
//Non existing asset asset70 should throw Error
// Non existing asset asset70 should throw Error
contract.submitTransaction("UpdateAsset", "asset70", "blue", "5", "Tomoko", "300");
} catch (Exception e) {
System.err.println("Expected an error on UpdateAsset of non-existing Asset: " + e);

View file

@ -232,9 +232,9 @@ async function findSoftHSMPKCS11Lib() {
if (typeof process.env.PKCS11_LIB === 'string' && process.env.PKCS11_LIB !== '') {
pkcsLibPath = process.env.PKCS11_LIB;
} else {
//
// Check common locations for PKCS library
//
for (const pathnameToTry of commonSoftHSMPathNames) {
if (fs.existsSync(pathnameToTry)) {
pkcsLibPath = pathnameToTry;

View file

@ -47,11 +47,10 @@ const org1UserId = 'appUser';
*/
// Delete the /fabric-samples/asset-transfer-basic/application-typescript/wallet directory
// and retry this application.
//
// The certificate authority must have been restarted and the saved certificates for the
// admin and application user are not valid. Deleting the wallet store will force these to be reset
// with the new certificate authority.
//
/**
* A test application to show basic queries operations with any of the asset-transfer-basic chaincodes

View file

@ -13,7 +13,7 @@ type SmartContract struct {
}
// Asset describes basic details of what makes up a simple asset
//Insert struct field in alphabetic order => to achieve determinism across languages
// Insert struct field in alphabetic order => to achieve determinism across languages
// golang keeps the order when marshal to json but doesn't order automatically
type Asset struct {
AppraisedValue int `json:"AppraisedValue"`

View file

@ -87,7 +87,7 @@ public final class AssetTransfer implements ContractInterface {
}
Asset asset = new Asset(assetID, color, size, owner, appraisedValue);
//Use Genson to convert the Asset into string, sort it alphabetically and serialize it into a json string
// Use Genson to convert the Asset into string, sort it alphabetically and serialize it into a json string
String sortedJson = genson.serialize(asset);
stub.putStringState(assetID, sortedJson);
@ -139,7 +139,7 @@ public final class AssetTransfer implements ContractInterface {
}
Asset newAsset = new Asset(assetID, color, size, owner, appraisedValue);
//Use Genson to convert the Asset into string, sort it alphabetically and serialize it into a json string
// Use Genson to convert the Asset into string, sort it alphabetically and serialize it into a json string
String sortedJson = genson.serialize(newAsset);
stub.putStringState(assetID, sortedJson);
return newAsset;
@ -201,7 +201,7 @@ public final class AssetTransfer implements ContractInterface {
Asset asset = genson.deserialize(assetJSON, Asset.class);
Asset newAsset = new Asset(asset.getAssetID(), asset.getColor(), asset.getSize(), newOwner, asset.getAppraisedValue());
//Use a Genson to conver the Asset into string, sort it alphabetically and serialize it into a json string
// Use a Genson to conver the Asset into string, sort it alphabetically and serialize it into a json string
String sortedJson = genson.serialize(newAsset);
stub.putStringState(assetID, sortedJson);

View file

@ -83,7 +83,7 @@ class AssetTransfer extends Contract {
Owner: owner,
AppraisedValue: appraisedValue,
};
//we insert data in alphabetic order using 'json-stringify-deterministic' and 'sort-keys-recursive'
// we insert data in alphabetic order using 'json-stringify-deterministic' and 'sort-keys-recursive'
await ctx.stub.putState(id, Buffer.from(stringify(sortKeysRecursive(asset))));
return JSON.stringify(asset);
}

View file

@ -43,10 +43,10 @@ export const createServer = async (): Promise<Application> => {
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
//define passport startegy
// define passport startegy
passport.use(fabricAPIKeyStrategy);
//initialize passport js
// initialize passport js
app.use(passport.initialize());
if (process.env.NODE_ENV === 'development') {

View file

@ -79,7 +79,7 @@ public final class AssetTransfer implements ContractInterface {
@Transaction(intent = Transaction.TYPE.SUBMIT)
public Asset CreateAsset(final Context ctx, final String assetID, final String color, final int size, final String owner, final int appraisedValue) {
ChaincodeStub stub = ctx.getStub();
//input validations
// input validations
String errorMessage = null;
if (assetID == null || assetID.equals("")) {
errorMessage = String.format("Empty input: assetID");
@ -167,7 +167,7 @@ public final class AssetTransfer implements ContractInterface {
@Transaction(intent = Transaction.TYPE.SUBMIT)
public Asset UpdateAsset(final Context ctx, final String assetID, final String color, final int size, final String owner, final int appraisedValue) {
ChaincodeStub stub = ctx.getStub();
//input validations
// input validations
String errorMessage = null;
if (assetID == null || assetID.equals("")) {
errorMessage = String.format("Empty input: assetID");
@ -217,7 +217,7 @@ public final class AssetTransfer implements ContractInterface {
// delete private details of asset
removePrivateData(ctx, assetID);
stub.delState(assetID); // delete the key from Statedb
stub.setEvent("DeleteAsset", asset.serialize()); //publish Event
stub.setEvent("DeleteAsset", asset.serialize()); // publish Event
}
private Asset getState(final Context ctx, final String assetID) {
@ -241,7 +241,7 @@ public final class AssetTransfer implements ContractInterface {
String clientMSPID = ctx.getClientIdentity().getMSPID();
String implicitCollectionName = getCollectionName(ctx);
String privData = null;
//only if ClientOrgMatchesPeerOrg
// only if ClientOrgMatchesPeerOrg
if (peerMSPID.equals(clientMSPID)) {
System.out.printf(" ReadPrivateData from collection %s, ID %s\n", implicitCollectionName, assetKey);
byte[] propJSON = ctx.getStub().getPrivateData(implicitCollectionName, assetKey);

View file

@ -65,7 +65,7 @@ public class App {
System.out.println("\n");
System.out.println("Submit Transaction: CreateAsset asset13");
//CreateAsset creates an asset with ID asset13, color yellow, owner Tom, size 5 and appraisedValue of 1300
// CreateAsset creates an asset with ID asset13, color yellow, owner Tom, size 5 and appraisedValue of 1300
contract.submitTransaction("CreateAsset", "asset13", "yellow", "5", "Tom", "1300");
System.out.println("\n");

View file

@ -75,7 +75,7 @@ async function main(): Promise<void> {
await getAssetsByRange(contractOrg1);
try{
//Attempt to transfer asset without prior aprroval from Org2, transaction expected to fail.
// Attempt to transfer asset without prior aprroval from Org2, transaction expected to fail.
console.log('\nAttempt TransferAsset without prior AgreeToTransfer');
await transferAsset(contractOrg1, assetID1);
doFail('TransferAsset transaction succeeded when it was expected to fail');

View file

@ -121,7 +121,7 @@ async function initContractFromOrg1Identity() {
try {
// Create a new gateway for connecting to Org's peer node.
const gatewayOrg1 = new Gateway();
//connect using Discovery enabled
// Connect using Discovery enabled
await gatewayOrg1.connect(ccpOrg1,
{ wallet: walletOrg1, identity: Org1UserId, discovery: { enabled: true, asLocalhost: true } });
@ -191,15 +191,15 @@ async function main() {
console.log('\n**************** As Org1 Client ****************');
console.log('Adding Assets to work with:\n--> Submit Transaction: CreateAsset ' + assetID1);
let statefulTxn = contractOrg1.createTransaction('CreateAsset');
//if you need to customize endorsement to specific set of Orgs, use setEndorsingOrganizations
//statefulTxn.setEndorsingOrganizations(mspOrg1);
// if you need to customize endorsement to specific set of Orgs, use setEndorsingOrganizations
// statefulTxn.setEndorsingOrganizations(mspOrg1);
let tmapData = Buffer.from(JSON.stringify(asset1Data));
statefulTxn.setTransient({
asset_properties: tmapData
});
result = await statefulTxn.submit();
//Add asset2
// Add asset2
console.log('\n--> Submit Transaction: CreateAsset ' + assetID2);
statefulTxn = contractOrg1.createTransaction('CreateAsset');
tmapData = Buffer.from(JSON.stringify(asset2Data));
@ -285,13 +285,13 @@ async function main() {
});
result = await statefulTxn.submit();
//Again ReadAsset : results will show that the buyer identity now owns the asset:
// Again ReadAsset : results will show that the buyer identity now owns the asset:
console.log('\n--> Evaluate Transaction: ReadAsset ' + assetID1);
result = await contractOrg1.evaluateTransaction('ReadAsset', assetID1);
console.log(`<-- result: ${prettyJSONString(result.toString())}`);
verifyAssetData(mspOrg1, result, assetID1, 'green', 20, Org2UserId);
//Confirm that transfer removed the private details from the Org1 collection:
// Confirm that transfer removed the private details from the Org1 collection:
console.log('\n--> Evaluate Transaction: ReadAssetPrivateDetails');
// ReadAssetPrivateDetails reads data from Org's private collection: Should return empty
result = await contractOrg1.evaluateTransaction('ReadAssetPrivateDetails', org1PrivateCollectionName, assetID1);
@ -307,7 +307,7 @@ async function main() {
console.log('\n********* Demo deleting asset **************');
let dataForDelete = { assetID: assetID2 };
try {
//Non-owner Org2 should not be able to DeleteAsset. Expect an error from DeleteAsset
// Non-owner Org2 should not be able to DeleteAsset. Expect an error from DeleteAsset
console.log('--> Attempt Transaction: as Org2 DeleteAsset ' + assetID2);
statefulTxn = contractOrg2.createTransaction('DeleteAsset');
tmapData = Buffer.from(JSON.stringify(dataForDelete));

View file

@ -23,7 +23,7 @@ func (s *SmartContract) ReadAsset(ctx contractapi.TransactionContextInterface, a
return nil, fmt.Errorf("failed to read asset: %v", err)
}
//No Asset found, return empty response
// No Asset found, return empty response
if assetJSON == nil {
log.Printf("%v does not exist in collection %v", assetID, assetCollection)
return nil, nil

View file

@ -53,7 +53,7 @@ func TestReadAssetPrivateDetails(t *testing.T) {
require.NoError(t, err)
require.Nil(t, assetBytes)
//read from the collection with no access
// read from the collection with no access
chaincodeStub.GetPrivateDataReturns(nil, fmt.Errorf("collection not found"))
assetBytes, err = assetTransferCC.ReadAssetPrivateDetails(transactionContext, myOrg2PrivCollection, "id1")
require.EqualError(t, err, "failed to read asset details: collection not found")
@ -72,7 +72,7 @@ func TestReadTransferAgreement(t *testing.T) {
transactionContext, chaincodeStub := prepMocksAsOrg1()
assetTransferCC := chaincode.SmartContract{}
//TransferAgreement does not exist
// TransferAgreement does not exist
assetBytes, err := assetTransferCC.ReadTransferAgreement(transactionContext, "id1")
require.NoError(t, err)
require.Nil(t, assetBytes)
@ -115,7 +115,7 @@ func TestQueryAssetByOwner(t *testing.T) {
func TestQueryAssets(t *testing.T) {
transactionContext, chaincodeStub := prepMocksAsOrg1()
//Iterator with no records
// Iterator with no records
iterator := &mocks.StateQueryIterator{}
iterator.HasNextReturns(false)
chaincodeStub.GetPrivateDataQueryResultReturns(iterator, nil)
@ -150,7 +150,7 @@ func TestQueryAssets(t *testing.T) {
func TestGetAssetByRange(t *testing.T) {
transactionContext, chaincodeStub := prepMocksAsOrg1()
//Iterator with no records
// Iterator with no records
iterator := &mocks.StateQueryIterator{}
iterator.HasNextReturns(false)
chaincodeStub.GetPrivateDataByRangeReturns(iterator, nil)

View file

@ -59,7 +59,7 @@ func (s *SmartContract) CreateAsset(ctx contractapi.TransactionContextInterface)
// Asset properties are private, therefore they get passed in transient field, instead of func args
transientAssetJSON, ok := transientMap["asset_properties"]
if !ok {
//log error to stdout
// log error to stdout
return fmt.Errorf("asset not found in the transient map input")
}
@ -450,7 +450,7 @@ func (s *SmartContract) DeleteAsset(ctx contractapi.TransactionContextInterface)
return fmt.Errorf("failed to infer private collection name for the org: %v", err)
}
//check the asset is in the caller org's private collection
// Check the asset is in the caller org's private collection
valAsbytes, err = ctx.GetStub().GetPrivateData(ownerCollection, assetDeleteInput.ID)
if err != nil {
return fmt.Errorf("failed to read asset from owner's Collection: %v", err)

View file

@ -127,7 +127,7 @@ func TestCreateAssetSuccessful(t *testing.T) {
setReturnAssetPropsInTransientMap(t, chaincodeStub, testAsset)
err := assetTransferCC.CreateAsset(transactionContext)
require.NoError(t, err)
//Validate PutPrivateData calls
// Validate PutPrivateData calls
calledCollection, calledId, _ := chaincodeStub.PutPrivateDataArgsForCall(0)
require.Equal(t, assetCollectionName, calledCollection)
require.Equal(t, "id1", calledId)
@ -149,7 +149,7 @@ func TestAgreeToTransferBadInput(t *testing.T) {
assetPrivDetail := &chaincode.AssetPrivateDetails{
ID: "id1",
//no AppraisedValue
// no AppraisedValue
}
setReturnAssetPrivateDetailsInTransientMap(t, chaincodeStub, assetPrivDetail)
origAsset := chaincode.Asset{
@ -165,7 +165,7 @@ func TestAgreeToTransferBadInput(t *testing.T) {
require.EqualError(t, err, "appraisedValue field must be a positive integer")
assetPrivDetail = &chaincode.AssetPrivateDetails{
//no ID
// no ID
AppraisedValue: 500,
}
setReturnAssetPrivateDetailsInTransientMap(t, chaincodeStub, assetPrivDetail)
@ -177,7 +177,7 @@ func TestAgreeToTransferBadInput(t *testing.T) {
AppraisedValue: 500,
}
setReturnAssetPrivateDetailsInTransientMap(t, chaincodeStub, assetPrivDetail)
//asset does not exist
// asset does not exist
setReturnPrivateDataInStub(t, chaincodeStub, nil)
err = assetTransferCC.AgreeToTransfer(transactionContext)
require.EqualError(t, err, "id1 does not exist")
@ -232,7 +232,7 @@ func TestTransferAssetBadInput(t *testing.T) {
BuyerMSP: myOrg2Msp,
}
setReturnAssetOwnerInTransientMap(t, chaincodeStub, assetNewOwner)
//asset does not exist
// asset does not exist
setReturnPrivateDataInStub(t, chaincodeStub, nil)
err = assetTransferCC.TransferAsset(transactionContext)
require.EqualError(t, err, "id1 does not exist")
@ -254,15 +254,15 @@ func TestTransferAssetSuccessful(t *testing.T) {
Owner: myOrg1Clientid,
}
setReturnPrivateDataInStub(t, chaincodeStub, &origAsset)
//to ensure we pass data hash verification
// to ensure we pass data hash verification
chaincodeStub.GetPrivateDataHashReturns([]byte("datahash"), nil)
//to ensure that ReadTransferAgreement call returns org2 client ID
// to ensure that ReadTransferAgreement call returns org2 client ID
chaincodeStub.GetPrivateDataReturnsOnCall(1, []byte(myOrg2Clientid), nil)
chaincodeStub.CreateCompositeKeyReturns(transferAgreementObjectType+"id1", nil)
err := assetTransferCC.TransferAsset(transactionContext)
require.NoError(t, err)
//Validate PutPrivateData calls
// Validate PutPrivateData calls
expectedNewAsset := origAsset
expectedNewAsset.Owner = myOrg2Clientid
expectedNewAssetBytes, err := json.Marshal(expectedNewAsset)
@ -289,7 +289,7 @@ func TestTransferAssetByNonOwner(t *testing.T) {
BuyerMSP: myOrg1Msp,
}
setReturnAssetOwnerInTransientMap(t, chaincodeStub, assetNewOwner)
//Try to transfer asset owned by Org2
// Try to transfer asset owned by Org2
org2Asset := chaincode.Asset{
ID: "id1",
Type: "testfulasset",
@ -318,10 +318,10 @@ func TestTransferAssetWithoutAnAgreement(t *testing.T) {
Owner: myOrg1Clientid,
}
setReturnPrivateDataInStub(t, chaincodeStub, &orgAsset)
//to ensure we pass data hash verification
// to ensure we pass data hash verification
chaincodeStub.GetPrivateDataHashReturns([]byte("datahash"), nil)
chaincodeStub.CreateCompositeKeyReturns(transferAgreementObjectType+"id1", nil)
//ReadTransferAgreement call returns no buyer client ID
// ReadTransferAgreement call returns no buyer client ID
chaincodeStub.GetPrivateDataReturnsOnCall(1, []byte{}, nil)
err := assetTransferCC.TransferAsset(transactionContext)
@ -346,7 +346,7 @@ func TestTransferAssetNonMatchingAppraisalValue(t *testing.T) {
}
setReturnPrivateDataInStub(t, chaincodeStub, &orgAsset)
chaincodeStub.CreateCompositeKeyReturns(transferAgreementObjectType+"id1", nil)
//data hash different in each collection
// data hash different in each collection
chaincodeStub.GetPrivateDataHashReturnsOnCall(0, []byte("datahash1"), nil)
chaincodeStub.GetPrivateDataHashReturnsOnCall(1, []byte("datahash2"), nil)
@ -369,7 +369,7 @@ func prepMocks(orgMSP, clientId string) (*mocks.TransactionContext, *mocks.Chain
clientIdentity := &mocks.ClientIdentity{}
clientIdentity.GetMSPIDReturns(orgMSP, nil)
clientIdentity.GetIDReturns(clientId, nil)
//set matching msp ID using peer shim env variable
// set matching msp ID using peer shim env variable
os.Setenv("CORE_PEER_LOCALMSPID", orgMSP)
transactionContext.GetClientIdentityReturns(clientIdentity)
return transactionContext, chaincodeStub

View file

@ -319,7 +319,7 @@ public final class AssetTransfer implements ContractInterface {
// write private data from this peer.
verifyClientOrgMatchesPeerOrg(ctx);
//Make submitting client the owner
// Make submitting client the owner
asset.setOwner(clientID);
System.out.printf("CreateAsset Put: collection %s, ID %s\n", ASSET_COLLECTION_NAME, assetID);
System.out.printf("Put: collection %s, ID %s\n", ASSET_COLLECTION_NAME, new String(asset.serialize()));
@ -328,7 +328,7 @@ public final class AssetTransfer implements ContractInterface {
// Get collection name for this organization.
String orgCollectionName = getCollectionName(ctx);
//Save AssetPrivateDetails to org collection
// Save AssetPrivateDetails to org collection
AssetPrivateDetails assetPriv = new AssetPrivateDetails(assetID, appraisedValue);
System.out.printf("Put AssetPrivateDetails: collection %s, ID %s\n", orgCollectionName, assetID);
stub.putPrivateData(orgCollectionName, assetID, assetPriv.serialize());
@ -392,12 +392,12 @@ public final class AssetTransfer implements ContractInterface {
verifyClientOrgMatchesPeerOrg(ctx);
//Save AssetPrivateDetails to org collection
// Save AssetPrivateDetails to org collection
System.out.printf("Put AssetPrivateDetails: collection %s, ID %s\n", orgCollectionName, assetID);
stub.putPrivateData(orgCollectionName, assetID, assetPriv.serialize());
String clientID = ctx.getClientIdentity().getId();
//Write the AgreeToTransfer key in assetCollection
// Write the AgreeToTransfer key in assetCollection
CompositeKey aggKey = stub.createCompositeKey(AGREEMENT_KEYPREFIX, assetID);
System.out.printf("AgreeToTransfer Put: collection %s, ID %s, Key %s\n", ASSET_COLLECTION_NAME, assetID, aggKey);
stub.putPrivateData(ASSET_COLLECTION_NAME, aggKey.toString(), clientID);
@ -470,15 +470,15 @@ public final class AssetTransfer implements ContractInterface {
String newOwner = transferAgreement.getBuyerID();
thisAsset.setOwner(newOwner);
//Save updated Asset to collection
// Save updated Asset to collection
System.out.printf("Transfer Asset: collection %s, ID %s to owner %s\n", ASSET_COLLECTION_NAME, assetID, newOwner);
stub.putPrivateData(ASSET_COLLECTION_NAME, assetID, thisAsset.serialize());
// delete the key from owners collection
// Delete the key from owners collection
String ownersCollectionName = getCollectionName(ctx);
stub.delPrivateData(ownersCollectionName, assetID);
//Delete the transfer agreement from the asset collection
// Delete the transfer agreement from the asset collection
CompositeKey aggKey = stub.createCompositeKey(AGREEMENT_KEYPREFIX, assetID);
System.out.printf("AgreeToTransfer deleteKey: collection %s, ID %s, Key %s\n", ASSET_COLLECTION_NAME, assetID, aggKey);
stub.delPrivateData(ASSET_COLLECTION_NAME, aggKey.toString());

View file

@ -134,7 +134,7 @@ export class AssetContract extends Contract {
sigsPolicies.push(signedBy);
});
// create the policy such that it requires any N signature's from all of the principals provided
// Create the policy such that it requires any N signature's from all of the principals provided
const allOf = {
n: nOrgs,
rules: sigsPolicies

View file

@ -13,7 +13,7 @@ import { RED, RESET } from './utils';
const channelName = 'mychannel';
const chaincodeName = 'secured';
//Use a random key so that we can run multiple times
// Use a random key so that we can run multiple times
const now = Date.now().toString();
let assetKey: string;

View file

@ -73,7 +73,7 @@ export const peerEndpointOrg2 = 'localhost:9051';
export const peerNameOrg1 = 'peer0.org1.example.com';
export const peerNameOrg2 = 'peer0.org2.example.com';
//Collection Names
// Collection Names
export const org1PrivateCollectionName = 'Org1MSPPrivateCollection';
export const org2PrivateCollectionName = 'Org2MSPPrivateCollection';

View file

@ -48,7 +48,7 @@ func checkForHigherBid(ctx contractapi.TransactionContextInterface, auctionPrice
if _, bidInAuction := revealedBidders[bidKey]; bidInAuction {
//bid is already revealed, no action to take
// bid is already revealed, no action to take
} else {

View file

@ -93,7 +93,7 @@ func checkForHigherBid(ctx contractapi.TransactionContextInterface, auctionPrice
if _, bidInAuction := revealedBidders[bidKey]; bidInAuction {
//bid is already revealed, no action to take
// bid is already revealed, no action to take
} else {

View file

@ -17,7 +17,7 @@ async function bid(ccp,wallet,user,orgMSP,auctionID,price) {
try {
const gateway = new Gateway();
//connect using Discovery enabled
// Connect using Discovery enabled
await gateway.connect(ccp,
{ wallet: wallet, identity: user, discovery: { enabled: true, asLocalhost: true } });

View file

@ -18,7 +18,7 @@ async function closeAuction(ccp,wallet,user,auctionID) {
const gateway = new Gateway();
//connect using Discovery enabled
// Connect using Discovery enabled
await gateway.connect(ccp,
{ wallet: wallet, identity: user, discovery: { enabled: true, asLocalhost: true } });

View file

@ -18,7 +18,7 @@ async function createAuction(ccp,wallet,user,auctionID,item) {
const gateway = new Gateway();
//connect using Discovery enabled
// Connect using Discovery enabled
await gateway.connect(ccp,
{ wallet: wallet, identity: user, discovery: { enabled: true, asLocalhost: true } });

View file

@ -18,7 +18,7 @@ async function endAuction(ccp,wallet,user,auctionID) {
const gateway = new Gateway();
//connect using Discovery enabled
// Connect using Discovery enabled
await gateway.connect(ccp,
{ wallet: wallet, identity: user, discovery: { enabled: true, asLocalhost: true } });

View file

@ -18,7 +18,7 @@ async function queryAuction(ccp,wallet,user,auctionID) {
const gateway = new Gateway();
//connect using Discovery enabled
// Connect using Discovery enabled
await gateway.connect(ccp,
{ wallet: wallet, identity: user, discovery: { enabled: true, asLocalhost: true } });

View file

@ -18,7 +18,7 @@ async function queryBid(ccp,wallet,user,auctionID,bidID) {
const gateway = new Gateway();
//connect using Discovery enabled
// Connect using Discovery enabled
await gateway.connect(ccp,
{ wallet: wallet, identity: user, discovery: { enabled: true, asLocalhost: true } });

View file

@ -27,7 +27,7 @@ async function addBid(ccp,wallet,user,auctionID,bidID) {
let bidString = await contract.evaluateTransaction('QueryBid',auctionID,bidID);
let bidJSON = JSON.parse(bidString);
//console.log('\n--> Evaluate Transaction: query the auction you want to join');
// console.log('\n--> Evaluate Transaction: query the auction you want to join');
let auctionString = await contract.evaluateTransaction('QueryAuction',auctionID);
// console.log('*** Result: Bid: ' + prettyJSONString(auctionString.toString()));
let auctionJSON = JSON.parse(auctionString);

View file

@ -28,7 +28,7 @@ async function submitBid(ccp,wallet,user,auctionID,bidID) {
const gateway = new Gateway();
//connect using Discovery enabled
// Connect using Discovery enabled
await gateway.connect(ccp,
{ wallet: wallet, identity: user, discovery: { enabled: true, asLocalhost: true } });

View file

@ -93,7 +93,7 @@ func checkForHigherBid(ctx contractapi.TransactionContextInterface, auctionPrice
if _, bidInAuction := revealedBidders[bidKey]; bidInAuction {
//bid is already revealed, no action to take
// bid is already revealed, no action to take
} else {

View file

@ -33,7 +33,7 @@ import (
pb "github.com/hyperledger/fabric-protos-go/peer"
)
//SmartContract is the data structure which represents this contract and on which various contract lifecycle functions are attached
// SmartContract is the data structure which represents this contract and on which various contract lifecycle functions are attached
type SmartContract struct {
}

View file

@ -117,7 +117,7 @@ type ToID struct {
// This function emits a TransferSingle event.
func (s *SmartContract) Mint(ctx contractapi.TransactionContextInterface, account string, id uint64, amount uint64) error {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -153,7 +153,7 @@ func (s *SmartContract) Mint(ctx contractapi.TransactionContextInterface, accoun
// This function emits a TransferBatch event.
func (s *SmartContract) MintBatch(ctx contractapi.TransactionContextInterface, account string, ids []uint64, amounts []uint64) error {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -209,7 +209,7 @@ func (s *SmartContract) MintBatch(ctx contractapi.TransactionContextInterface, a
// This function triggers a TransferSingle event.
func (s *SmartContract) Burn(ctx contractapi.TransactionContextInterface, account string, id uint64, amount uint64) error {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -248,7 +248,7 @@ func (s *SmartContract) Burn(ctx contractapi.TransactionContextInterface, accoun
// This function emits a TransferBatch event.
func (s *SmartContract) BurnBatch(ctx contractapi.TransactionContextInterface, account string, ids []uint64, amounts []uint64) error {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -291,7 +291,7 @@ func (s *SmartContract) BurnBatch(ctx contractapi.TransactionContextInterface, a
// This function triggers a TransferSingle event
func (s *SmartContract) TransferFrom(ctx contractapi.TransactionContextInterface, sender string, recipient string, id uint64, amount uint64) error {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -347,7 +347,7 @@ func (s *SmartContract) TransferFrom(ctx contractapi.TransactionContextInterface
// This function triggers a TransferBatch event
func (s *SmartContract) BatchTransferFrom(ctx contractapi.TransactionContextInterface, sender string, recipient string, ids []uint64, amounts []uint64) error {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -422,7 +422,7 @@ func (s *SmartContract) BatchTransferFrom(ctx contractapi.TransactionContextInte
// This function triggers a TransferBatchMultiRecipient event
func (s *SmartContract) BatchTransferFromMultiRecipient(ctx contractapi.TransactionContextInterface, sender string, recipients []string, ids []uint64, amounts []uint64) error {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -504,7 +504,7 @@ func (s *SmartContract) IsApprovedForAll(ctx contractapi.TransactionContextInter
// _isApprovedForAll returns true if operator is approved to transfer account's tokens.
func _isApprovedForAll(ctx contractapi.TransactionContextInterface, account string, operator string) (bool, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return false, fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -539,7 +539,7 @@ func _isApprovedForAll(ctx contractapi.TransactionContextInterface, account stri
// SetApprovalForAll returns true if operator is approved to transfer account's tokens.
func (s *SmartContract) SetApprovalForAll(ctx contractapi.TransactionContextInterface, operator string, approved bool) error {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -589,7 +589,7 @@ func (s *SmartContract) SetApprovalForAll(ctx contractapi.TransactionContextInte
// BalanceOf returns the balance of the given account
func (s *SmartContract) BalanceOf(ctx contractapi.TransactionContextInterface, account string, id uint64) (uint64, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return 0, fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -604,7 +604,7 @@ func (s *SmartContract) BalanceOf(ctx contractapi.TransactionContextInterface, a
// BalanceOfBatch returns the balance of multiple account/token pairs
func (s *SmartContract) BalanceOfBatch(ctx contractapi.TransactionContextInterface, accounts []string, ids []uint64) ([]uint64, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return nil, fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -633,7 +633,7 @@ func (s *SmartContract) BalanceOfBatch(ctx contractapi.TransactionContextInterfa
// ClientAccountBalance returns the balance of the requesting client's account
func (s *SmartContract) ClientAccountBalance(ctx contractapi.TransactionContextInterface, id uint64) (uint64, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return 0, fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -656,7 +656,7 @@ func (s *SmartContract) ClientAccountBalance(ctx contractapi.TransactionContextI
// Users can use this function to get their own account id, which they can then give to others as the payment address
func (s *SmartContract) ClientAccountID(ctx contractapi.TransactionContextInterface) (string, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -678,7 +678,7 @@ func (s *SmartContract) ClientAccountID(ctx contractapi.TransactionContextInterf
// This function triggers URI event for each token id
func (s *SmartContract) SetURI(ctx contractapi.TransactionContextInterface, uri string) error {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -708,7 +708,7 @@ func (s *SmartContract) SetURI(ctx contractapi.TransactionContextInterface, uri
// URI returns the URI
func (s *SmartContract) URI(ctx contractapi.TransactionContextInterface, id uint64) (string, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -731,7 +731,7 @@ func (s *SmartContract) URI(ctx contractapi.TransactionContextInterface, id uint
func (s *SmartContract) BroadcastTokenExistance(ctx contractapi.TransactionContextInterface, id uint64) error {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -762,7 +762,7 @@ func (s *SmartContract) BroadcastTokenExistance(ctx contractapi.TransactionConte
func (s *SmartContract) Name(ctx contractapi.TransactionContextInterface) (string, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -784,7 +784,7 @@ func (s *SmartContract) Name(ctx contractapi.TransactionContextInterface) (strin
func (s *SmartContract) Symbol(ctx contractapi.TransactionContextInterface) (string, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -815,7 +815,7 @@ func (s *SmartContract) Initialize(ctx contractapi.TransactionContextInterface,
return false, fmt.Errorf("client is not authorized to initialize contract")
}
//check contract options are not already set, client is not authorized to change them once intitialized
// Check contract options are not already set, client is not authorized to change them once intitialized
bytes, err := ctx.GetStub().GetState(nameKey)
if err != nil {
return false, fmt.Errorf("failed to get Name: %v", err)
@ -1120,7 +1120,7 @@ func sortedKeysToID(m map[ToID]uint64) []ToID {
return keys
}
//Checks that contract options have been already initialized
// Checks that contract options have been already initialized
func checkInitialized(ctx contractapi.TransactionContextInterface) (bool, error) {
tokenName, err := ctx.GetStub().GetState(nameKey)
if err != nil {

View file

@ -37,7 +37,7 @@ type event struct {
// This function triggers a Transfer event
func (s *SmartContract) Mint(ctx contractapi.TransactionContextInterface, amount int) error {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -135,7 +135,7 @@ func (s *SmartContract) Mint(ctx contractapi.TransactionContextInterface, amount
// This function triggers a Transfer event
func (s *SmartContract) Burn(ctx contractapi.TransactionContextInterface, amount int) error {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -231,7 +231,7 @@ func (s *SmartContract) Burn(ctx contractapi.TransactionContextInterface, amount
// This function triggers a Transfer event
func (s *SmartContract) Transfer(ctx contractapi.TransactionContextInterface, recipient string, amount int) error {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -268,7 +268,7 @@ func (s *SmartContract) Transfer(ctx contractapi.TransactionContextInterface, re
// BalanceOf returns the balance of the given account
func (s *SmartContract) BalanceOf(ctx contractapi.TransactionContextInterface, account string) (int, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return 0, fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -293,7 +293,7 @@ func (s *SmartContract) BalanceOf(ctx contractapi.TransactionContextInterface, a
// ClientAccountBalance returns the balance of the requesting client's account
func (s *SmartContract) ClientAccountBalance(ctx contractapi.TransactionContextInterface) (int, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return 0, fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -326,7 +326,7 @@ func (s *SmartContract) ClientAccountBalance(ctx contractapi.TransactionContextI
// Users can use this function to get their own account id, which they can then give to others as the payment address
func (s *SmartContract) ClientAccountID(ctx contractapi.TransactionContextInterface) (string, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -347,7 +347,7 @@ func (s *SmartContract) ClientAccountID(ctx contractapi.TransactionContextInterf
// TotalSupply returns the total token supply
func (s *SmartContract) TotalSupply(ctx contractapi.TransactionContextInterface) (int, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return 0, fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -381,7 +381,7 @@ func (s *SmartContract) TotalSupply(ctx contractapi.TransactionContextInterface)
// This function triggers an Approval event
func (s *SmartContract) Approve(ctx contractapi.TransactionContextInterface, spender string, value int) error {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -427,7 +427,7 @@ func (s *SmartContract) Approve(ctx contractapi.TransactionContextInterface, spe
// Allowance returns the amount still available for the spender to withdraw from the owner
func (s *SmartContract) Allowance(ctx contractapi.TransactionContextInterface, owner string, spender string) (int, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return 0, fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -466,7 +466,7 @@ func (s *SmartContract) Allowance(ctx contractapi.TransactionContextInterface, o
// This function triggers a Transfer event
func (s *SmartContract) TransferFrom(ctx contractapi.TransactionContextInterface, from string, to string, value int) error {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -539,7 +539,7 @@ func (s *SmartContract) TransferFrom(ctx contractapi.TransactionContextInterface
func (s *SmartContract) Name(ctx contractapi.TransactionContextInterface) (string, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -561,7 +561,7 @@ func (s *SmartContract) Name(ctx contractapi.TransactionContextInterface) (strin
func (s *SmartContract) Symbol(ctx contractapi.TransactionContextInterface) (string, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -593,7 +593,7 @@ func (s *SmartContract) Initialize(ctx contractapi.TransactionContextInterface,
return false, fmt.Errorf("client is not authorized to initialize contract")
}
//check contract options are not already set, client is not authorized to change them once intitialized
// Check contract options are not already set, client is not authorized to change them once intitialized
bytes, err := ctx.GetStub().GetState(nameKey)
if err != nil {
return false, fmt.Errorf("failed to get Name: %v", err)
@ -702,7 +702,7 @@ func add(b int, q int) (int, error) {
return sum, nil
}
//Checks that contract options have been already initialized
// Checks that contract options have been already initialized
func checkInitialized(ctx contractapi.TransactionContextInterface) (bool, error) {
tokenName, err := ctx.GetStub().GetState(nameKey)
if err != nil {

View file

@ -77,7 +77,7 @@ public final class ERC20TokenContract implements ContractInterface {
"Client is not authorized to mint new tokens", UNAUTHORIZED_SENDER.toString());
}
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
// Get ID of submitting client identity
@ -132,7 +132,7 @@ public final class ERC20TokenContract implements ContractInterface {
"Client is not authorized to burn tokens", UNAUTHORIZED_SENDER.toString());
}
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
String minter = ctx.getClientIdentity().getId();
@ -181,7 +181,7 @@ public final class ERC20TokenContract implements ContractInterface {
*/
@Transaction(intent = Transaction.TYPE.SUBMIT)
public void Transfer(final Context ctx, final String to, final long value) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
String from = ctx.getClientIdentity().getId();
this.transferHelper(ctx, from, to, value);
@ -198,7 +198,7 @@ public final class ERC20TokenContract implements ContractInterface {
*/
@Transaction(intent = Transaction.TYPE.EVALUATE)
public long BalanceOf(final Context ctx, final String owner) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
ChaincodeStub stub = ctx.getStub();
CompositeKey balanceKey = stub.createCompositeKey(BALANCE_PREFIX.getValue(), owner);
@ -219,7 +219,7 @@ public final class ERC20TokenContract implements ContractInterface {
*/
@Transaction(intent = Transaction.TYPE.EVALUATE)
public long ClientAccountBalance(final Context ctx) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
// Get ID of submitting client identity
ChaincodeStub stub = ctx.getStub();
@ -244,7 +244,7 @@ public final class ERC20TokenContract implements ContractInterface {
*/
@Transaction(intent = Transaction.TYPE.EVALUATE)
public String ClientAccountID(final Context ctx) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
// Get ID of submitting client identity
return ctx.getClientIdentity().getId();
@ -258,7 +258,7 @@ public final class ERC20TokenContract implements ContractInterface {
*/
@Transaction(intent = Transaction.TYPE.EVALUATE)
public long TotalSupply(final Context ctx) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
String totalSupply = ctx.getStub().getStringState(TOTAL_SUPPLY_KEY.getValue());
if (stringIsNullOrEmpty(totalSupply)) {
@ -277,7 +277,7 @@ public final class ERC20TokenContract implements ContractInterface {
*/
@Transaction(intent = Transaction.TYPE.SUBMIT)
public void Approve(final Context ctx, final String spender, final long value) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
ChaincodeStub stub = ctx.getStub();
String owner = ctx.getClientIdentity().getId();
@ -302,7 +302,7 @@ public final class ERC20TokenContract implements ContractInterface {
*/
@Transaction(intent = Transaction.TYPE.SUBMIT)
public long Allowance(final Context ctx, final String owner, final String spender) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
ChaincodeStub stub = ctx.getStub();
CompositeKey allowanceKey =
@ -330,7 +330,7 @@ public final class ERC20TokenContract implements ContractInterface {
@Transaction(intent = Transaction.TYPE.SUBMIT)
public void TransferFrom(
final Context ctx, final String from, final String to, final long value) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
String spender = ctx.getClientIdentity().getId();
ChaincodeStub stub = ctx.getStub();
@ -437,7 +437,7 @@ public final class ERC20TokenContract implements ContractInterface {
"Client is not authorized to initialize contract", UNAUTHORIZED_SENDER.toString());
}
//check contract options are not already set, client is not authorized to change them once intitialized
// Check contract options are not already set, client is not authorized to change them once intitialized
String tokenName = stub.getStringState(ContractConstants.NAME_KEY.getValue());
if (!stringIsNullOrEmpty(tokenName)) {
throw new ChaincodeException("contract options are already set, client is not authorized to change them");
@ -458,7 +458,7 @@ public final class ERC20TokenContract implements ContractInterface {
*/
@Transaction(intent = Transaction.TYPE.EVALUATE)
public String TokenName(final Context ctx) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
String tokenName = ctx.getStub().getStringState(ContractConstants.NAME_KEY.getValue());
if (stringIsNullOrEmpty(tokenName)) {
@ -475,7 +475,7 @@ public final class ERC20TokenContract implements ContractInterface {
*/
@Transaction(intent = Transaction.TYPE.EVALUATE)
public String TokenSymbol(final Context ctx) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
String tokenSymbol = ctx.getStub().getStringState(SYMBOL_KEY.getValue());
if (stringIsNullOrEmpty(tokenSymbol)) {
@ -493,7 +493,7 @@ public final class ERC20TokenContract implements ContractInterface {
*/
@Transaction(intent = Transaction.TYPE.EVALUATE)
public int Decimals(final Context ctx) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
String decimals = ctx.getStub().getStringState(DECIMALS_KEY.getValue());
if (stringIsNullOrEmpty(decimals)) {

View file

@ -31,7 +31,7 @@ class TokenERC20Contract extends Contract {
*/
async TokenName(ctx) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
const nameBytes = await ctx.stub.getState(nameKey);
@ -47,7 +47,7 @@ class TokenERC20Contract extends Contract {
*/
async Symbol(ctx) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
const symbolBytes = await ctx.stub.getState(symbolKey);
@ -63,7 +63,7 @@ class TokenERC20Contract extends Contract {
*/
async Decimals(ctx) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
const decimalsBytes = await ctx.stub.getState(decimalsKey);
@ -79,7 +79,7 @@ class TokenERC20Contract extends Contract {
*/
async TotalSupply(ctx) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
const totalSupplyBytes = await ctx.stub.getState(totalSupplyKey);
@ -96,7 +96,7 @@ class TokenERC20Contract extends Contract {
*/
async BalanceOf(ctx, owner) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
const balanceKey = ctx.stub.createCompositeKey(balancePrefix, [owner]);
@ -121,7 +121,7 @@ class TokenERC20Contract extends Contract {
*/
async Transfer(ctx, to, value) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
const from = ctx.clientIdentity.getID();
@ -149,7 +149,7 @@ class TokenERC20Contract extends Contract {
*/
async TransferFrom(ctx, from, to, value) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
const spender = ctx.clientIdentity.getID();
@ -253,7 +253,7 @@ class TokenERC20Contract extends Contract {
*/
async Approve(ctx, spender, value) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
const owner = ctx.clientIdentity.getID();
@ -281,7 +281,7 @@ class TokenERC20Contract extends Contract {
*/
async Allowance(ctx, owner, spender) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
const allowanceKey = ctx.stub.createCompositeKey(allowancePrefix, [owner, spender]);
@ -313,7 +313,7 @@ class TokenERC20Contract extends Contract {
throw new Error('client is not authorized to initialize contract');
}
//check contract options are not already set, client is not authorized to change them once intitialized
// Check contract options are not already set, client is not authorized to change them once intitialized
const nameBytes = await ctx.stub.getState(nameKey);
if (nameBytes && nameBytes.length > 0) {
throw new Error('contract options are already set, client is not authorized to change them');
@ -336,7 +336,7 @@ class TokenERC20Contract extends Contract {
*/
async Mint(ctx, amount) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
// Check minter authorization - this sample assumes Org1 is the central banker with privilege to mint new tokens
@ -396,7 +396,7 @@ class TokenERC20Contract extends Contract {
*/
async Burn(ctx, amount) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
// Check minter authorization - this sample assumes Org1 is the central banker with privilege to burn tokens
@ -444,7 +444,7 @@ class TokenERC20Contract extends Contract {
*/
async ClientAccountBalance(ctx) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
// Get ID of submitting client identity
@ -465,7 +465,7 @@ class TokenERC20Contract extends Contract {
// Users can use this function to get their own account id, which they can then give to others as the payment address
async ClientAccountID(ctx) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
// Get ID of submitting client identity
@ -473,7 +473,7 @@ class TokenERC20Contract extends Contract {
return clientAccountID;
}
//Checks that contract options have been already initialized
// Checks that contract options have been already initialized
async CheckInitialized(ctx){
const nameBytes = await ctx.stub.getState(nameKey);
if (!nameBytes || nameBytes.length === 0) {

View file

@ -202,14 +202,14 @@ describe('Chaincode', () => {
describe('#Initialize', () => {
it('should work', async () => {
//we consider it has already been initialized in the before-each statement
// We consider it has already been initialized in the before-each statement
sinon.assert.calledWith(mockStub.putState, 'name', Buffer.from('some name'));
sinon.assert.calledWith(mockStub.putState, 'symbol', Buffer.from('some symbol'));
sinon.assert.calledWith(mockStub.putState, 'decimals', Buffer.from('2'));
});
it('should failed if called a second time', async () => {
//we consider it has already been initialized in the before-each statement
// We consider it has already been initialized in the before-each statement
await expect(await token.Initialize(ctx, 'some name', 'some symbol', '2'))
.to.be.rejectedWith(Error, 'contract options are already set, client is not authorized to change them');
});

View file

@ -61,7 +61,7 @@ func _nftExists(ctx contractapi.TransactionContextInterface, tokenId string) boo
// returns {int} The number of non-fungible tokens owned by the owner, possibly zero
func (c *TokenERC721Contract) BalanceOf(ctx contractapi.TransactionContextInterface, owner string) int {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
panic("failed to check if contract ia already initialized:" + err.Error())
@ -96,7 +96,7 @@ func (c *TokenERC721Contract) BalanceOf(ctx contractapi.TransactionContextInterf
// returns {String} Return the owner of the non-fungible token
func (c *TokenERC721Contract) OwnerOf(ctx contractapi.TransactionContextInterface, tokenId string) (string, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -119,7 +119,7 @@ func (c *TokenERC721Contract) OwnerOf(ctx contractapi.TransactionContextInterfac
// returns {Boolean} Return whether the approval was successful or not
func (c *TokenERC721Contract) Approve(ctx contractapi.TransactionContextInterface, operator string, tokenId string) (bool, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return false, fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -182,7 +182,7 @@ func (c *TokenERC721Contract) Approve(ctx contractapi.TransactionContextInterfac
// returns {Boolean} Return whether the approval was successful or not
func (c *TokenERC721Contract) SetApprovalForAll(ctx contractapi.TransactionContextInterface, operator string, approved bool) (bool, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return false, fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -237,7 +237,7 @@ func (c *TokenERC721Contract) SetApprovalForAll(ctx contractapi.TransactionConte
// returns {Boolean} Return true if the operator is an approved operator for the owner, false otherwise
func (c *TokenERC721Contract) IsApprovedForAll(ctx contractapi.TransactionContextInterface, owner string, operator string) (bool, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return false, fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -274,7 +274,7 @@ func (c *TokenERC721Contract) IsApprovedForAll(ctx contractapi.TransactionContex
// returns {Object} Return the approved client for this non-fungible token, or null if there is none
func (c *TokenERC721Contract) GetApproved(ctx contractapi.TransactionContextInterface, tokenId string) (string, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return "false", fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -299,7 +299,7 @@ func (c *TokenERC721Contract) GetApproved(ctx contractapi.TransactionContextInte
func (c *TokenERC721Contract) TransferFrom(ctx contractapi.TransactionContextInterface, from string, to string, tokenId string) (bool, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return false, fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -406,7 +406,7 @@ func (c *TokenERC721Contract) TransferFrom(ctx contractapi.TransactionContextInt
func (c *TokenERC721Contract) Name(ctx contractapi.TransactionContextInterface) (string, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -428,7 +428,7 @@ func (c *TokenERC721Contract) Name(ctx contractapi.TransactionContextInterface)
func (c *TokenERC721Contract) Symbol(ctx contractapi.TransactionContextInterface) (string, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -451,7 +451,7 @@ func (c *TokenERC721Contract) Symbol(ctx contractapi.TransactionContextInterface
func (c *TokenERC721Contract) TokenURI(ctx contractapi.TransactionContextInterface, tokenId string) (string, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -476,7 +476,7 @@ func (c *TokenERC721Contract) TokenURI(ctx contractapi.TransactionContextInterfa
func (c *TokenERC721Contract) TotalSupply(ctx contractapi.TransactionContextInterface) int {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
panic("failed to check if contract ia already initialized:" + err.Error())
@ -550,7 +550,7 @@ func (c *TokenERC721Contract) Initialize(ctx contractapi.TransactionContextInter
func (c *TokenERC721Contract) MintWithTokenURI(ctx contractapi.TransactionContextInterface, tokenId string, tokenURI string) (*Nft, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return nil, fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -646,7 +646,7 @@ func (c *TokenERC721Contract) MintWithTokenURI(ctx contractapi.TransactionContex
// returns {Boolean} Return whether the burn was successful or not
func (c *TokenERC721Contract) Burn(ctx contractapi.TransactionContextInterface, tokenId string) (bool, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return false, fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -720,7 +720,7 @@ func (c *TokenERC721Contract) Burn(ctx contractapi.TransactionContextInterface,
// returns {Number} Returns the account balance
func (c *TokenERC721Contract) ClientAccountBalance(ctx contractapi.TransactionContextInterface) (int, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return 0, fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -751,7 +751,7 @@ func (c *TokenERC721Contract) ClientAccountBalance(ctx contractapi.TransactionCo
func (c *TokenERC721Contract) ClientAccountID(ctx contractapi.TransactionContextInterface) (string, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -775,7 +775,7 @@ func (c *TokenERC721Contract) ClientAccountID(ctx contractapi.TransactionContext
return clientAccount, nil
}
//Checks that contract options have been already initialized
// Checks that contract options have been already initialized
func checkInitialized(ctx contractapi.TransactionContextInterface) (bool, error) {
tokenName, err := ctx.GetStub().GetState(nameKey)
if err != nil {

View file

@ -54,7 +54,7 @@ public class ERC721TokenContract implements ContractInterface {
*/
@Transaction(intent = Transaction.TYPE.EVALUATE)
public long BalanceOf(final Context ctx, final String owner) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
final ChaincodeStub stub = ctx.getStub();
final CompositeKey balanceKey =
@ -78,7 +78,7 @@ public class ERC721TokenContract implements ContractInterface {
*/
@Transaction(intent = Transaction.TYPE.EVALUATE)
public String OwnerOf(final Context ctx, final String tokenId) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
final NFT nft = this._readNft(ctx, tokenId);
if (stringIsNullOrEmpty(nft.getOwner())) {
@ -98,7 +98,7 @@ public class ERC721TokenContract implements ContractInterface {
*/
@Transaction(intent = Transaction.TYPE.EVALUATE)
public boolean IsApprovedForAll(final Context ctx, final String owner, final String operator) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
final ChaincodeStub stub = ctx.getStub();
final CompositeKey approvalKey =
@ -122,7 +122,7 @@ public class ERC721TokenContract implements ContractInterface {
*/
@Transaction(intent = Transaction.TYPE.SUBMIT)
public void Approve(final Context ctx, final String operator, final String tokenId) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
final ChaincodeStub stub = ctx.getStub();
final String sender = ctx.getClientIdentity().getId();
@ -152,7 +152,7 @@ public class ERC721TokenContract implements ContractInterface {
*/
@Transaction(intent = Transaction.TYPE.SUBMIT)
public void SetApprovalForAll(final Context ctx, final String operator, final boolean approved) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
final String sender = ctx.getClientIdentity().getId();
final ChaincodeStub stub = ctx.getStub();
@ -173,7 +173,7 @@ public class ERC721TokenContract implements ContractInterface {
*/
@Transaction(intent = Transaction.TYPE.EVALUATE)
public String GetApproved(final Context ctx, final String tokenId) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
final NFT nft = this._readNft(ctx, tokenId);
return nft.getApproved();
@ -190,7 +190,7 @@ public class ERC721TokenContract implements ContractInterface {
@Transaction(intent = Transaction.TYPE.SUBMIT)
public void TransferFrom(
final Context ctx, final String from, final String to, final String tokenId) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
final String sender = ctx.getClientIdentity().getId();
final ChaincodeStub stub = ctx.getStub();
@ -249,7 +249,7 @@ public class ERC721TokenContract implements ContractInterface {
*/
@Transaction(intent = Transaction.TYPE.EVALUATE)
public String Name(final Context ctx) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
return ctx.getStub().getStringState(ContractConstants.NAMEKEY.getValue());
}
@ -262,7 +262,7 @@ public class ERC721TokenContract implements ContractInterface {
*/
@Transaction(intent = Transaction.TYPE.EVALUATE)
public String Symbol(final Context ctx) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
return ctx.getStub().getStringState(ContractConstants.SYMBOLKEY.getValue());
}
@ -276,7 +276,7 @@ public class ERC721TokenContract implements ContractInterface {
*/
@Transaction(intent = Transaction.TYPE.EVALUATE)
public String TokenURI(final Context ctx, final String tokenId) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
final NFT nft = this._readNft(ctx, tokenId);
return nft.getTokenURI();
@ -295,7 +295,7 @@ public class ERC721TokenContract implements ContractInterface {
*/
@Transaction(intent = Transaction.TYPE.EVALUATE)
public long TotalSupply(final Context ctx) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
final ChaincodeStub stub = ctx.getStub();
final CompositeKey nftKey = stub.createCompositeKey(ContractConstants.NFT.getValue());
@ -331,7 +331,7 @@ public class ERC721TokenContract implements ContractInterface {
"Client is not authorized to initialize the contract (set the name and symbol of the token)");
}
//check contract options are not already set, client is not authorized to change them once intitialized
// Check contract options are not already set, client is not authorized to change them once intitialized
String tokenName = stub.getStringState(ContractConstants.NAMEKEY.getValue());
if (!stringIsNullOrEmpty(tokenName)) {
throw new ChaincodeException("contract options are already set, client is not authorized to change them");
@ -351,7 +351,7 @@ public class ERC721TokenContract implements ContractInterface {
*/
@Transaction(intent = Transaction.TYPE.SUBMIT)
public NFT MintWithTokenURI(final Context ctx, final String tokenId, final String tokenURI) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
final String clientMSPID = ctx.getClientIdentity().getMSPID();
final ChaincodeStub stub = ctx.getStub();
@ -392,7 +392,7 @@ public class ERC721TokenContract implements ContractInterface {
*/
@Transaction(intent = Transaction.TYPE.SUBMIT)
public void Burn(final Context ctx, final String tokenId) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
final ChaincodeStub stub = ctx.getStub();
final String owner = ctx.getClientIdentity().getId();
@ -424,7 +424,7 @@ public class ERC721TokenContract implements ContractInterface {
*/
@Transaction(intent = Transaction.TYPE.EVALUATE)
public long ClientAccountBalance(final Context ctx) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
return this.BalanceOf(ctx, ctx.getClientIdentity().getId());
}
@ -439,7 +439,7 @@ public class ERC721TokenContract implements ContractInterface {
*/
@Transaction(intent = Transaction.TYPE.EVALUATE)
public String ClientAccountID(final Context ctx) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
this.checkInitialized(ctx);
return ctx.getClientIdentity().getId();
}

View file

@ -25,7 +25,7 @@ class TokenERC721Contract extends Contract {
* @returns {Number} The number of non-fungible tokens owned by the owner, possibly zero
*/
async BalanceOf(ctx, owner) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
// There is a key record for every non-fungible token in the format of balancePrefix.owner.tokenId.
@ -50,7 +50,7 @@ class TokenERC721Contract extends Contract {
* @returns {String} Return the owner of the non-fungible token
*/
async OwnerOf(ctx, tokenId) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
const nft = await this._readNFT(ctx, tokenId);
@ -73,7 +73,7 @@ class TokenERC721Contract extends Contract {
* @returns {Boolean} Return whether the transfer was successful or not
*/
async TransferFrom(ctx, from, to, tokenId) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
const sender = ctx.clientIdentity.getID();
@ -127,7 +127,7 @@ class TokenERC721Contract extends Contract {
* @returns {Boolean} Return whether the approval was successful or not
*/
async Approve(ctx, approved, tokenId) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
const sender = ctx.clientIdentity.getID();
@ -165,7 +165,7 @@ class TokenERC721Contract extends Contract {
* @returns {Boolean} Return whether the approval was successful or not
*/
async SetApprovalForAll(ctx, operator, approved) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
const sender = ctx.clientIdentity.getID();
@ -189,7 +189,7 @@ class TokenERC721Contract extends Contract {
* @returns {Object} Return the approved client for this non-fungible token, or null if there is none
*/
async GetApproved(ctx, tokenId) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
const nft = await this._readNFT(ctx, tokenId);
@ -205,7 +205,7 @@ class TokenERC721Contract extends Contract {
* @returns {Boolean} Return true if the operator is an approved operator for the owner, false otherwise
*/
async IsApprovedForAll(ctx, owner, operator) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
const approvalKey = ctx.stub.createCompositeKey(approvalPrefix, [owner, operator]);
@ -230,7 +230,7 @@ class TokenERC721Contract extends Contract {
* @returns {String} Returns the name of the token
*/
async Name(ctx) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
const nameAsBytes = await ctx.stub.getState(nameKey);
@ -244,7 +244,7 @@ class TokenERC721Contract extends Contract {
* @returns {String} Returns the symbol of the token
*/
async Symbol(ctx) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
const symbolAsBytes = await ctx.stub.getState(symbolKey);
@ -259,7 +259,7 @@ class TokenERC721Contract extends Contract {
* @returns {String} Returns the URI of the token
*/
async TokenURI(ctx, tokenId) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
const nft = await this._readNFT(ctx, tokenId);
@ -276,7 +276,7 @@ class TokenERC721Contract extends Contract {
* where each one of them has an assigned and queryable owner.
*/
async TotalSupply(ctx) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
// There is a key record for every non-fungible token in the format of nftPrefix.tokenId.
@ -310,7 +310,7 @@ class TokenERC721Contract extends Contract {
throw new Error('client is not authorized to set the name and symbol of the token');
}
//check contract options are not already set, client is not authorized to change them once intitialized
// Check contract options are not already set, client is not authorized to change them once intitialized
const nameBytes = await ctx.stub.getState(nameKey);
if (nameBytes && nameBytes.length > 0) {
throw new Error('contract options are already set, client is not authorized to change them');
@ -330,7 +330,7 @@ class TokenERC721Contract extends Contract {
* @returns {Object} Return the non-fungible token object
*/
async MintWithTokenURI(ctx, tokenId, tokenURI) {
//check contract options are already set first to execute the function
// Check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
// Check minter authorization - this sample assumes Org1 is the issuer with privilege to mint a new token
@ -382,7 +382,7 @@ class TokenERC721Contract extends Contract {
* @returns {Boolean} Return whether the burn was successful or not
*/
async Burn(ctx, tokenId) {
//check contract options are already set first to execute the function
// check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
const owner = ctx.clientIdentity.getID();
@ -432,7 +432,7 @@ class TokenERC721Contract extends Contract {
* @returns {Number} Returns the account balance
*/
async ClientAccountBalance(ctx) {
//check contract options are already set first to execute the function
// check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
// Get ID of submitting client identity
@ -444,7 +444,7 @@ class TokenERC721Contract extends Contract {
// In this implementation, the client account ID is the clientId itself.
// Users can use this function to get their own account id, which they can then give to others as the payment address
async ClientAccountID(ctx) {
//check contract options are already set first to execute the function
// check contract options are already set first to execute the function
await this.CheckInitialized(ctx);
// Get ID of submitting client identity
@ -452,7 +452,7 @@ class TokenERC721Contract extends Contract {
return clientAccountID;
}
//Checks that contract options have been already initialized
// Checks that contract options have been already initialized
async CheckInitialized(ctx){
const nameBytes = await ctx.stub.getState(nameKey);
if (!nameBytes || nameBytes.length === 0) {

View file

@ -28,7 +28,7 @@ const totalSupplyKey = "totalSupply"
// Mint creates a new unspent transaction output (UTXO) owned by the minter
func (s *SmartContract) Mint(ctx contractapi.TransactionContextInterface, amount int) (*UTXO, error) {
//check if contract has been intilized first
// check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return nil, fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -77,7 +77,7 @@ func (s *SmartContract) Mint(ctx contractapi.TransactionContextInterface, amount
// Transfer transfers UTXOs containing tokens from client to recipient(s)
func (s *SmartContract) Transfer(ctx contractapi.TransactionContextInterface, utxoInputKeys []string, utxoOutputs []UTXO) ([]UTXO, error) {
//check if contract has been intilized first
// check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return nil, fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -181,7 +181,7 @@ func (s *SmartContract) Transfer(ctx contractapi.TransactionContextInterface, ut
// ClientUTXOs returns all UTXOs owned by the calling client
func (s *SmartContract) ClientUTXOs(ctx contractapi.TransactionContextInterface) ([]*UTXO, error) {
//check if contract has been intilized first
// check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return nil, fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -243,7 +243,7 @@ func (s *SmartContract) ClientUTXOs(ctx contractapi.TransactionContextInterface)
// Users can use this function to get their own client id, which they can then give to others as the payment address
func (s *SmartContract) ClientID(ctx contractapi.TransactionContextInterface) (string, error) {
//check if contract has been intilized first
// check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -266,7 +266,7 @@ func (s *SmartContract) ClientID(ctx contractapi.TransactionContextInterface) (s
func (s *SmartContract) Name(ctx contractapi.TransactionContextInterface) (string, error) {
//check if contract has been intilized first
// check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -288,7 +288,7 @@ func (s *SmartContract) Name(ctx contractapi.TransactionContextInterface) (strin
func (s *SmartContract) Symbol(ctx contractapi.TransactionContextInterface) (string, error) {
//check if contract has been intilized first
// Check if contract has been intilized first
initialized, err := checkInitialized(ctx)
if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err)
@ -319,7 +319,7 @@ func (s *SmartContract) Initialize(ctx contractapi.TransactionContextInterface,
return false, fmt.Errorf("client is not authorized to initialize contract")
}
//check contract options are not already set, client is not authorized to change them once intitialized
// check contract options are not already set, client is not authorized to change them once intitialized
bytes, err := ctx.GetStub().GetState(nameKey)
if err != nil {
return false, fmt.Errorf("failed to get Name: %v", err)
@ -343,7 +343,7 @@ func (s *SmartContract) Initialize(ctx contractapi.TransactionContextInterface,
return true, nil
}
//Checks that contract options have been already initialized
// Checks that contract options have been already initialized
func checkInitialized(ctx contractapi.TransactionContextInterface) (bool, error) {
tokenName, err := ctx.GetStub().GetState(nameKey)
if err != nil {