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 // 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; // to see if the caller has the "abac.creator" attribute with a value of true;
// if not, return an error. // if not, return an error.
//
err := ctx.GetClientIdentity().AssertAttributeValue("abac.creator", "true") err := ctx.GetClientIdentity().AssertAttributeValue("abac.creator", "true")
if err != nil { if err != nil {
return fmt.Errorf("submitting client not authorized to create asset, does not have abac.creator role") return fmt.Errorf("submitting client not authorized to create asset, does not have abac.creator role")

View file

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

View file

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

View file

@ -121,7 +121,7 @@ async function initContractFromOrg1Identity() {
try { try {
// Create a new gateway for connecting to Org's peer node. // Create a new gateway for connecting to Org's peer node.
const gatewayOrg1 = new Gateway(); const gatewayOrg1 = new Gateway();
//connect using Discovery enabled // Connect using Discovery enabled
await gatewayOrg1.connect(ccpOrg1, await gatewayOrg1.connect(ccpOrg1,
{ wallet: walletOrg1, identity: Org1UserId, discovery: { enabled: true, asLocalhost: true } }); { wallet: walletOrg1, identity: Org1UserId, discovery: { enabled: true, asLocalhost: true } });

View file

@ -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) 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) valAsbytes, err = ctx.GetStub().GetPrivateData(ownerCollection, assetDeleteInput.ID)
if err != nil { if err != nil {
return fmt.Errorf("failed to read asset from owner's Collection: %v", err) return fmt.Errorf("failed to read asset from owner's Collection: %v", err)

View file

@ -474,7 +474,7 @@ public final class AssetTransfer implements ContractInterface {
System.out.printf("Transfer Asset: collection %s, ID %s to owner %s\n", ASSET_COLLECTION_NAME, assetID, newOwner); 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()); stub.putPrivateData(ASSET_COLLECTION_NAME, assetID, thisAsset.serialize());
// delete the key from owners collection // Delete the key from owners collection
String ownersCollectionName = getCollectionName(ctx); String ownersCollectionName = getCollectionName(ctx);
stub.delPrivateData(ownersCollectionName, assetID); stub.delPrivateData(ownersCollectionName, assetID);

View file

@ -134,7 +134,7 @@ export class AssetContract extends Contract {
sigsPolicies.push(signedBy); 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 = { const allOf = {
n: nOrgs, n: nOrgs,
rules: sigsPolicies rules: sigsPolicies

View file

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

View file

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

View file

@ -117,7 +117,7 @@ type ToID struct {
// This function emits a TransferSingle event. // This function emits a TransferSingle event.
func (s *SmartContract) Mint(ctx contractapi.TransactionContextInterface, account string, id uint64, amount uint64) error { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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. // This function emits a TransferBatch event.
func (s *SmartContract) MintBatch(ctx contractapi.TransactionContextInterface, account string, ids []uint64, amounts []uint64) error { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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. // This function triggers a TransferSingle event.
func (s *SmartContract) Burn(ctx contractapi.TransactionContextInterface, account string, id uint64, amount uint64) error { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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. // This function emits a TransferBatch event.
func (s *SmartContract) BurnBatch(ctx contractapi.TransactionContextInterface, account string, ids []uint64, amounts []uint64) error { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 // This function triggers a TransferSingle event
func (s *SmartContract) TransferFrom(ctx contractapi.TransactionContextInterface, sender string, recipient string, id uint64, amount uint64) error { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 // This function triggers a TransferBatch event
func (s *SmartContract) BatchTransferFrom(ctx contractapi.TransactionContextInterface, sender string, recipient string, ids []uint64, amounts []uint64) error { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 // This function triggers a TransferBatchMultiRecipient event
func (s *SmartContract) BatchTransferFromMultiRecipient(ctx contractapi.TransactionContextInterface, sender string, recipients []string, ids []uint64, amounts []uint64) error { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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. // _isApprovedForAll returns true if operator is approved to transfer account's tokens.
func _isApprovedForAll(ctx contractapi.TransactionContextInterface, account string, operator string) (bool, error) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return false, fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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. // SetApprovalForAll returns true if operator is approved to transfer account's tokens.
func (s *SmartContract) SetApprovalForAll(ctx contractapi.TransactionContextInterface, operator string, approved bool) error { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 // BalanceOf returns the balance of the given account
func (s *SmartContract) BalanceOf(ctx contractapi.TransactionContextInterface, account string, id uint64) (uint64, error) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return 0, fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 // BalanceOfBatch returns the balance of multiple account/token pairs
func (s *SmartContract) BalanceOfBatch(ctx contractapi.TransactionContextInterface, accounts []string, ids []uint64) ([]uint64, error) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 // ClientAccountBalance returns the balance of the requesting client's account
func (s *SmartContract) ClientAccountBalance(ctx contractapi.TransactionContextInterface, id uint64) (uint64, error) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return 0, fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 // 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) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 // This function triggers URI event for each token id
func (s *SmartContract) SetURI(ctx contractapi.TransactionContextInterface, uri string) error { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 // URI returns the URI
func (s *SmartContract) URI(ctx contractapi.TransactionContextInterface, id uint64) (string, error) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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") 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) bytes, err := ctx.GetStub().GetState(nameKey)
if err != nil { if err != nil {
return false, fmt.Errorf("failed to get Name: %v", err) return false, fmt.Errorf("failed to get Name: %v", err)

View file

@ -37,7 +37,7 @@ type event struct {
// This function triggers a Transfer event // This function triggers a Transfer event
func (s *SmartContract) Mint(ctx contractapi.TransactionContextInterface, amount int) error { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 // This function triggers a Transfer event
func (s *SmartContract) Burn(ctx contractapi.TransactionContextInterface, amount int) error { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 // This function triggers a Transfer event
func (s *SmartContract) Transfer(ctx contractapi.TransactionContextInterface, recipient string, amount int) error { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 // BalanceOf returns the balance of the given account
func (s *SmartContract) BalanceOf(ctx contractapi.TransactionContextInterface, account string) (int, error) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return 0, fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 // ClientAccountBalance returns the balance of the requesting client's account
func (s *SmartContract) ClientAccountBalance(ctx contractapi.TransactionContextInterface) (int, error) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return 0, fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 // 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) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 // TotalSupply returns the total token supply
func (s *SmartContract) TotalSupply(ctx contractapi.TransactionContextInterface) (int, error) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return 0, fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 // This function triggers an Approval event
func (s *SmartContract) Approve(ctx contractapi.TransactionContextInterface, spender string, value int) error { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 // 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) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return 0, fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 // This function triggers a Transfer event
func (s *SmartContract) TransferFrom(ctx contractapi.TransactionContextInterface, from string, to string, value int) error { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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") 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) bytes, err := ctx.GetStub().GetState(nameKey)
if err != nil { if err != nil {
return false, fmt.Errorf("failed to get Name: %v", err) return false, fmt.Errorf("failed to get Name: %v", err)

View file

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

View file

@ -31,7 +31,7 @@ class TokenERC20Contract extends Contract {
*/ */
async TokenName(ctx) { 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); await this.CheckInitialized(ctx);
const nameBytes = await ctx.stub.getState(nameKey); const nameBytes = await ctx.stub.getState(nameKey);
@ -47,7 +47,7 @@ class TokenERC20Contract extends Contract {
*/ */
async Symbol(ctx) { 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); await this.CheckInitialized(ctx);
const symbolBytes = await ctx.stub.getState(symbolKey); const symbolBytes = await ctx.stub.getState(symbolKey);
@ -63,7 +63,7 @@ class TokenERC20Contract extends Contract {
*/ */
async Decimals(ctx) { 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); await this.CheckInitialized(ctx);
const decimalsBytes = await ctx.stub.getState(decimalsKey); const decimalsBytes = await ctx.stub.getState(decimalsKey);
@ -79,7 +79,7 @@ class TokenERC20Contract extends Contract {
*/ */
async TotalSupply(ctx) { 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); await this.CheckInitialized(ctx);
const totalSupplyBytes = await ctx.stub.getState(totalSupplyKey); const totalSupplyBytes = await ctx.stub.getState(totalSupplyKey);
@ -96,7 +96,7 @@ class TokenERC20Contract extends Contract {
*/ */
async BalanceOf(ctx, owner) { 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); await this.CheckInitialized(ctx);
const balanceKey = ctx.stub.createCompositeKey(balancePrefix, [owner]); const balanceKey = ctx.stub.createCompositeKey(balancePrefix, [owner]);
@ -121,7 +121,7 @@ class TokenERC20Contract extends Contract {
*/ */
async Transfer(ctx, to, value) { 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); await this.CheckInitialized(ctx);
const from = ctx.clientIdentity.getID(); const from = ctx.clientIdentity.getID();
@ -149,7 +149,7 @@ class TokenERC20Contract extends Contract {
*/ */
async TransferFrom(ctx, from, to, value) { 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); await this.CheckInitialized(ctx);
const spender = ctx.clientIdentity.getID(); const spender = ctx.clientIdentity.getID();
@ -253,7 +253,7 @@ class TokenERC20Contract extends Contract {
*/ */
async Approve(ctx, spender, value) { 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); await this.CheckInitialized(ctx);
const owner = ctx.clientIdentity.getID(); const owner = ctx.clientIdentity.getID();
@ -281,7 +281,7 @@ class TokenERC20Contract extends Contract {
*/ */
async Allowance(ctx, owner, spender) { 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); await this.CheckInitialized(ctx);
const allowanceKey = ctx.stub.createCompositeKey(allowancePrefix, [owner, spender]); 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'); 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); const nameBytes = await ctx.stub.getState(nameKey);
if (nameBytes && nameBytes.length > 0) { if (nameBytes && nameBytes.length > 0) {
throw new Error('contract options are already set, client is not authorized to change them'); 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) { 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); await this.CheckInitialized(ctx);
// Check minter authorization - this sample assumes Org1 is the central banker with privilege to mint new tokens // 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) { 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); await this.CheckInitialized(ctx);
// Check minter authorization - this sample assumes Org1 is the central banker with privilege to burn tokens // 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) { 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); await this.CheckInitialized(ctx);
// Get ID of submitting client identity // 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 // 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) { 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); await this.CheckInitialized(ctx);
// Get ID of submitting client identity // Get ID of submitting client identity

View file

@ -202,14 +202,14 @@ describe('Chaincode', () => {
describe('#Initialize', () => { describe('#Initialize', () => {
it('should work', async () => { 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, 'name', Buffer.from('some name'));
sinon.assert.calledWith(mockStub.putState, 'symbol', Buffer.from('some symbol')); sinon.assert.calledWith(mockStub.putState, 'symbol', Buffer.from('some symbol'));
sinon.assert.calledWith(mockStub.putState, 'decimals', Buffer.from('2')); sinon.assert.calledWith(mockStub.putState, 'decimals', Buffer.from('2'));
}); });
it('should failed if called a second time', async () => { 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')) 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'); .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 // returns {int} The number of non-fungible tokens owned by the owner, possibly zero
func (c *TokenERC721Contract) BalanceOf(ctx contractapi.TransactionContextInterface, owner string) int { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
panic("failed to check if contract ia already initialized:" + err.Error()) 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 // returns {String} Return the owner of the non-fungible token
func (c *TokenERC721Contract) OwnerOf(ctx contractapi.TransactionContextInterface, tokenId string) (string, error) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 // returns {Boolean} Return whether the approval was successful or not
func (c *TokenERC721Contract) Approve(ctx contractapi.TransactionContextInterface, operator string, tokenId string) (bool, error) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return false, fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 // returns {Boolean} Return whether the approval was successful or not
func (c *TokenERC721Contract) SetApprovalForAll(ctx contractapi.TransactionContextInterface, operator string, approved bool) (bool, error) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return false, fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 // 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) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return false, fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 // 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) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return "false", fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return false, fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
panic("failed to check if contract ia already initialized:" + err.Error()) 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) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 // returns {Boolean} Return whether the burn was successful or not
func (c *TokenERC721Contract) Burn(ctx contractapi.TransactionContextInterface, tokenId string) (bool, error) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return false, fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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 // returns {Number} Returns the account balance
func (c *TokenERC721Contract) ClientAccountBalance(ctx contractapi.TransactionContextInterface) (int, error) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return 0, fmt.Errorf("failed to check if contract ia already initialized: %v", err) 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) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err) return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err)

View file

@ -54,7 +54,7 @@ public class ERC721TokenContract implements ContractInterface {
*/ */
@Transaction(intent = Transaction.TYPE.EVALUATE) @Transaction(intent = Transaction.TYPE.EVALUATE)
public long BalanceOf(final Context ctx, final String owner) { 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); this.checkInitialized(ctx);
final ChaincodeStub stub = ctx.getStub(); final ChaincodeStub stub = ctx.getStub();
final CompositeKey balanceKey = final CompositeKey balanceKey =
@ -78,7 +78,7 @@ public class ERC721TokenContract implements ContractInterface {
*/ */
@Transaction(intent = Transaction.TYPE.EVALUATE) @Transaction(intent = Transaction.TYPE.EVALUATE)
public String OwnerOf(final Context ctx, final String tokenId) { 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); this.checkInitialized(ctx);
final NFT nft = this._readNft(ctx, tokenId); final NFT nft = this._readNft(ctx, tokenId);
if (stringIsNullOrEmpty(nft.getOwner())) { if (stringIsNullOrEmpty(nft.getOwner())) {
@ -98,7 +98,7 @@ public class ERC721TokenContract implements ContractInterface {
*/ */
@Transaction(intent = Transaction.TYPE.EVALUATE) @Transaction(intent = Transaction.TYPE.EVALUATE)
public boolean IsApprovedForAll(final Context ctx, final String owner, final String operator) { 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); this.checkInitialized(ctx);
final ChaincodeStub stub = ctx.getStub(); final ChaincodeStub stub = ctx.getStub();
final CompositeKey approvalKey = final CompositeKey approvalKey =
@ -122,7 +122,7 @@ public class ERC721TokenContract implements ContractInterface {
*/ */
@Transaction(intent = Transaction.TYPE.SUBMIT) @Transaction(intent = Transaction.TYPE.SUBMIT)
public void Approve(final Context ctx, final String operator, final String tokenId) { 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); this.checkInitialized(ctx);
final ChaincodeStub stub = ctx.getStub(); final ChaincodeStub stub = ctx.getStub();
final String sender = ctx.getClientIdentity().getId(); final String sender = ctx.getClientIdentity().getId();
@ -152,7 +152,7 @@ public class ERC721TokenContract implements ContractInterface {
*/ */
@Transaction(intent = Transaction.TYPE.SUBMIT) @Transaction(intent = Transaction.TYPE.SUBMIT)
public void SetApprovalForAll(final Context ctx, final String operator, final boolean approved) { 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); this.checkInitialized(ctx);
final String sender = ctx.getClientIdentity().getId(); final String sender = ctx.getClientIdentity().getId();
final ChaincodeStub stub = ctx.getStub(); final ChaincodeStub stub = ctx.getStub();
@ -173,7 +173,7 @@ public class ERC721TokenContract implements ContractInterface {
*/ */
@Transaction(intent = Transaction.TYPE.EVALUATE) @Transaction(intent = Transaction.TYPE.EVALUATE)
public String GetApproved(final Context ctx, final String tokenId) { 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); this.checkInitialized(ctx);
final NFT nft = this._readNft(ctx, tokenId); final NFT nft = this._readNft(ctx, tokenId);
return nft.getApproved(); return nft.getApproved();
@ -190,7 +190,7 @@ public class ERC721TokenContract implements ContractInterface {
@Transaction(intent = Transaction.TYPE.SUBMIT) @Transaction(intent = Transaction.TYPE.SUBMIT)
public void TransferFrom( public void TransferFrom(
final Context ctx, final String from, final String to, final String tokenId) { 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); this.checkInitialized(ctx);
final String sender = ctx.getClientIdentity().getId(); final String sender = ctx.getClientIdentity().getId();
final ChaincodeStub stub = ctx.getStub(); final ChaincodeStub stub = ctx.getStub();
@ -249,7 +249,7 @@ public class ERC721TokenContract implements ContractInterface {
*/ */
@Transaction(intent = Transaction.TYPE.EVALUATE) @Transaction(intent = Transaction.TYPE.EVALUATE)
public String Name(final Context ctx) { 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); this.checkInitialized(ctx);
return ctx.getStub().getStringState(ContractConstants.NAMEKEY.getValue()); return ctx.getStub().getStringState(ContractConstants.NAMEKEY.getValue());
} }
@ -262,7 +262,7 @@ public class ERC721TokenContract implements ContractInterface {
*/ */
@Transaction(intent = Transaction.TYPE.EVALUATE) @Transaction(intent = Transaction.TYPE.EVALUATE)
public String Symbol(final Context ctx) { 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); this.checkInitialized(ctx);
return ctx.getStub().getStringState(ContractConstants.SYMBOLKEY.getValue()); return ctx.getStub().getStringState(ContractConstants.SYMBOLKEY.getValue());
} }
@ -276,7 +276,7 @@ public class ERC721TokenContract implements ContractInterface {
*/ */
@Transaction(intent = Transaction.TYPE.EVALUATE) @Transaction(intent = Transaction.TYPE.EVALUATE)
public String TokenURI(final Context ctx, final String tokenId) { 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); this.checkInitialized(ctx);
final NFT nft = this._readNft(ctx, tokenId); final NFT nft = this._readNft(ctx, tokenId);
return nft.getTokenURI(); return nft.getTokenURI();
@ -295,7 +295,7 @@ public class ERC721TokenContract implements ContractInterface {
*/ */
@Transaction(intent = Transaction.TYPE.EVALUATE) @Transaction(intent = Transaction.TYPE.EVALUATE)
public long TotalSupply(final Context ctx) { 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); this.checkInitialized(ctx);
final ChaincodeStub stub = ctx.getStub(); final ChaincodeStub stub = ctx.getStub();
final CompositeKey nftKey = stub.createCompositeKey(ContractConstants.NFT.getValue()); 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)"); "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()); String tokenName = stub.getStringState(ContractConstants.NAMEKEY.getValue());
if (!stringIsNullOrEmpty(tokenName)) { if (!stringIsNullOrEmpty(tokenName)) {
throw new ChaincodeException("contract options are already set, client is not authorized to change them"); 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) @Transaction(intent = Transaction.TYPE.SUBMIT)
public NFT MintWithTokenURI(final Context ctx, final String tokenId, final String tokenURI) { 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); this.checkInitialized(ctx);
final String clientMSPID = ctx.getClientIdentity().getMSPID(); final String clientMSPID = ctx.getClientIdentity().getMSPID();
final ChaincodeStub stub = ctx.getStub(); final ChaincodeStub stub = ctx.getStub();
@ -392,7 +392,7 @@ public class ERC721TokenContract implements ContractInterface {
*/ */
@Transaction(intent = Transaction.TYPE.SUBMIT) @Transaction(intent = Transaction.TYPE.SUBMIT)
public void Burn(final Context ctx, final String tokenId) { 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); this.checkInitialized(ctx);
final ChaincodeStub stub = ctx.getStub(); final ChaincodeStub stub = ctx.getStub();
final String owner = ctx.getClientIdentity().getId(); final String owner = ctx.getClientIdentity().getId();
@ -424,7 +424,7 @@ public class ERC721TokenContract implements ContractInterface {
*/ */
@Transaction(intent = Transaction.TYPE.EVALUATE) @Transaction(intent = Transaction.TYPE.EVALUATE)
public long ClientAccountBalance(final Context ctx) { 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); this.checkInitialized(ctx);
return this.BalanceOf(ctx, ctx.getClientIdentity().getId()); return this.BalanceOf(ctx, ctx.getClientIdentity().getId());
} }
@ -439,7 +439,7 @@ public class ERC721TokenContract implements ContractInterface {
*/ */
@Transaction(intent = Transaction.TYPE.EVALUATE) @Transaction(intent = Transaction.TYPE.EVALUATE)
public String ClientAccountID(final Context ctx) { 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); this.checkInitialized(ctx);
return ctx.getClientIdentity().getId(); 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 * @returns {Number} The number of non-fungible tokens owned by the owner, possibly zero
*/ */
async BalanceOf(ctx, owner) { 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); await this.CheckInitialized(ctx);
// There is a key record for every non-fungible token in the format of balancePrefix.owner.tokenId. // 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 * @returns {String} Return the owner of the non-fungible token
*/ */
async OwnerOf(ctx, tokenId) { 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); await this.CheckInitialized(ctx);
const nft = await this._readNFT(ctx, tokenId); 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 * @returns {Boolean} Return whether the transfer was successful or not
*/ */
async TransferFrom(ctx, from, to, tokenId) { 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); await this.CheckInitialized(ctx);
const sender = ctx.clientIdentity.getID(); const sender = ctx.clientIdentity.getID();
@ -127,7 +127,7 @@ class TokenERC721Contract extends Contract {
* @returns {Boolean} Return whether the approval was successful or not * @returns {Boolean} Return whether the approval was successful or not
*/ */
async Approve(ctx, approved, tokenId) { 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); await this.CheckInitialized(ctx);
const sender = ctx.clientIdentity.getID(); const sender = ctx.clientIdentity.getID();
@ -165,7 +165,7 @@ class TokenERC721Contract extends Contract {
* @returns {Boolean} Return whether the approval was successful or not * @returns {Boolean} Return whether the approval was successful or not
*/ */
async SetApprovalForAll(ctx, operator, approved) { 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); await this.CheckInitialized(ctx);
const sender = ctx.clientIdentity.getID(); 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 * @returns {Object} Return the approved client for this non-fungible token, or null if there is none
*/ */
async GetApproved(ctx, tokenId) { 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); await this.CheckInitialized(ctx);
const nft = await this._readNFT(ctx, tokenId); 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 * @returns {Boolean} Return true if the operator is an approved operator for the owner, false otherwise
*/ */
async IsApprovedForAll(ctx, owner, operator) { 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); await this.CheckInitialized(ctx);
const approvalKey = ctx.stub.createCompositeKey(approvalPrefix, [owner, operator]); const approvalKey = ctx.stub.createCompositeKey(approvalPrefix, [owner, operator]);
@ -230,7 +230,7 @@ class TokenERC721Contract extends Contract {
* @returns {String} Returns the name of the token * @returns {String} Returns the name of the token
*/ */
async Name(ctx) { 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); await this.CheckInitialized(ctx);
const nameAsBytes = await ctx.stub.getState(nameKey); const nameAsBytes = await ctx.stub.getState(nameKey);
@ -244,7 +244,7 @@ class TokenERC721Contract extends Contract {
* @returns {String} Returns the symbol of the token * @returns {String} Returns the symbol of the token
*/ */
async Symbol(ctx) { 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); await this.CheckInitialized(ctx);
const symbolAsBytes = await ctx.stub.getState(symbolKey); const symbolAsBytes = await ctx.stub.getState(symbolKey);
@ -259,7 +259,7 @@ class TokenERC721Contract extends Contract {
* @returns {String} Returns the URI of the token * @returns {String} Returns the URI of the token
*/ */
async TokenURI(ctx, tokenId) { 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); await this.CheckInitialized(ctx);
const nft = await this._readNFT(ctx, tokenId); 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. * where each one of them has an assigned and queryable owner.
*/ */
async TotalSupply(ctx) { 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); await this.CheckInitialized(ctx);
// There is a key record for every non-fungible token in the format of nftPrefix.tokenId. // 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'); 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); const nameBytes = await ctx.stub.getState(nameKey);
if (nameBytes && nameBytes.length > 0) { if (nameBytes && nameBytes.length > 0) {
throw new Error('contract options are already set, client is not authorized to change them'); 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 * @returns {Object} Return the non-fungible token object
*/ */
async MintWithTokenURI(ctx, tokenId, tokenURI) { 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); await this.CheckInitialized(ctx);
// Check minter authorization - this sample assumes Org1 is the issuer with privilege to mint a new token // Check minter authorization - this sample assumes Org1 is the issuer with privilege to mint a new token

View file

@ -288,7 +288,7 @@ func (s *SmartContract) Name(ctx contractapi.TransactionContextInterface) (strin
func (s *SmartContract) Symbol(ctx contractapi.TransactionContextInterface) (string, error) { 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) initialized, err := checkInitialized(ctx)
if err != nil { if err != nil {
return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err) return "", fmt.Errorf("failed to check if contract ia already initialized: %v", err)