mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-25 11:05:10 +00:00
added more comment consistancy fix
Signed-off-by: Ali Shahverdi <ali@Alis-MacBook-Pro.local>
This commit is contained in:
parent
0959261d07
commit
615f2fe6f9
19 changed files with 138 additions and 139 deletions
|
|
@ -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")
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ public class App {
|
||||||
|
|
||||||
System.out.println("\n");
|
System.out.println("\n");
|
||||||
System.out.println("Submit Transaction: CreateAsset asset13");
|
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");
|
contract.submitTransaction("CreateAsset", "asset13", "yellow", "5", "Tom", "1300");
|
||||||
|
|
||||||
System.out.println("\n");
|
System.out.println("\n");
|
||||||
|
|
@ -92,7 +92,7 @@ public class App {
|
||||||
try {
|
try {
|
||||||
System.out.println("\n");
|
System.out.println("\n");
|
||||||
System.out.println("Submit Transaction: UpdateAsset asset70");
|
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");
|
contract.submitTransaction("UpdateAsset", "asset70", "blue", "5", "Tomoko", "300");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("Expected an error on UpdateAsset of non-existing Asset: " + e);
|
System.err.println("Expected an error on UpdateAsset of non-existing Asset: " + e);
|
||||||
|
|
|
||||||
|
|
@ -231,9 +231,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;
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ type SmartContract struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Asset describes basic details of what makes up a simple asset
|
// 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
|
// golang keeps the order when marshal to json but doesn't order automatically
|
||||||
type Asset struct {
|
type Asset struct {
|
||||||
AppraisedValue int `json:"AppraisedValue"`
|
AppraisedValue int `json:"AppraisedValue"`
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ public final class AssetTransfer implements ContractInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
Asset asset = new Asset(assetID, color, size, owner, appraisedValue);
|
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);
|
String sortedJson = genson.serialize(asset);
|
||||||
stub.putStringState(assetID, sortedJson);
|
stub.putStringState(assetID, sortedJson);
|
||||||
|
|
||||||
|
|
@ -139,7 +139,7 @@ public final class AssetTransfer implements ContractInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
Asset newAsset = new Asset(assetID, color, size, owner, appraisedValue);
|
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);
|
String sortedJson = genson.serialize(newAsset);
|
||||||
stub.putStringState(assetID, sortedJson);
|
stub.putStringState(assetID, sortedJson);
|
||||||
return newAsset;
|
return newAsset;
|
||||||
|
|
@ -201,7 +201,7 @@ public final class AssetTransfer implements ContractInterface {
|
||||||
Asset asset = genson.deserialize(assetJSON, Asset.class);
|
Asset asset = genson.deserialize(assetJSON, Asset.class);
|
||||||
|
|
||||||
Asset newAsset = new Asset(asset.getAssetID(), asset.getColor(), asset.getSize(), newOwner, asset.getAppraisedValue());
|
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);
|
String sortedJson = genson.serialize(newAsset);
|
||||||
stub.putStringState(assetID, sortedJson);
|
stub.putStringState(assetID, sortedJson);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ class AssetTransfer extends Contract {
|
||||||
Owner: owner,
|
Owner: owner,
|
||||||
AppraisedValue: appraisedValue,
|
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))));
|
await ctx.stub.putState(id, Buffer.from(stringify(sortKeysRecursive(asset))));
|
||||||
return JSON.stringify(asset);
|
return JSON.stringify(asset);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,10 +43,10 @@ export const createServer = async (): Promise<Application> => {
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use(express.urlencoded({ extended: true }));
|
app.use(express.urlencoded({ extended: true }));
|
||||||
|
|
||||||
//define passport startegy
|
// define passport startegy
|
||||||
passport.use(fabricAPIKeyStrategy);
|
passport.use(fabricAPIKeyStrategy);
|
||||||
|
|
||||||
//initialize passport js
|
// initialize passport js
|
||||||
app.use(passport.initialize());
|
app.use(passport.initialize());
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'development') {
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ public final class AssetTransfer implements ContractInterface {
|
||||||
@Transaction(intent = Transaction.TYPE.SUBMIT)
|
@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) {
|
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();
|
ChaincodeStub stub = ctx.getStub();
|
||||||
//input validations
|
// input validations
|
||||||
String errorMessage = null;
|
String errorMessage = null;
|
||||||
if (assetID == null || assetID.equals("")) {
|
if (assetID == null || assetID.equals("")) {
|
||||||
errorMessage = String.format("Empty input: assetID");
|
errorMessage = String.format("Empty input: assetID");
|
||||||
|
|
@ -167,7 +167,7 @@ public final class AssetTransfer implements ContractInterface {
|
||||||
@Transaction(intent = Transaction.TYPE.SUBMIT)
|
@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) {
|
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();
|
ChaincodeStub stub = ctx.getStub();
|
||||||
//input validations
|
// input validations
|
||||||
String errorMessage = null;
|
String errorMessage = null;
|
||||||
if (assetID == null || assetID.equals("")) {
|
if (assetID == null || assetID.equals("")) {
|
||||||
errorMessage = String.format("Empty input: assetID");
|
errorMessage = String.format("Empty input: assetID");
|
||||||
|
|
@ -217,7 +217,7 @@ public final class AssetTransfer implements ContractInterface {
|
||||||
// delete private details of asset
|
// delete private details of asset
|
||||||
removePrivateData(ctx, assetID);
|
removePrivateData(ctx, assetID);
|
||||||
stub.delState(assetID); // delete the key from Statedb
|
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) {
|
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 clientMSPID = ctx.getClientIdentity().getMSPID();
|
||||||
String implicitCollectionName = getCollectionName(ctx);
|
String implicitCollectionName = getCollectionName(ctx);
|
||||||
String privData = null;
|
String privData = null;
|
||||||
//only if ClientOrgMatchesPeerOrg
|
// only if ClientOrgMatchesPeerOrg
|
||||||
if (peerMSPID.equals(clientMSPID)) {
|
if (peerMSPID.equals(clientMSPID)) {
|
||||||
System.out.printf(" ReadPrivateData from collection %s, ID %s\n", implicitCollectionName, assetKey);
|
System.out.printf(" ReadPrivateData from collection %s, ID %s\n", implicitCollectionName, assetKey);
|
||||||
byte[] propJSON = ctx.getStub().getPrivateData(implicitCollectionName, assetKey);
|
byte[] propJSON = ctx.getStub().getPrivateData(implicitCollectionName, assetKey);
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ public class App {
|
||||||
|
|
||||||
System.out.println("\n");
|
System.out.println("\n");
|
||||||
System.out.println("Submit Transaction: CreateAsset asset13");
|
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");
|
contract.submitTransaction("CreateAsset", "asset13", "yellow", "5", "Tom", "1300");
|
||||||
|
|
||||||
System.out.println("\n");
|
System.out.println("\n");
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
@ -1120,7 +1120,7 @@ func sortedKeysToID(m map[ToID]uint64) []ToID {
|
||||||
return keys
|
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) {
|
func checkInitialized(ctx contractapi.TransactionContextInterface) (bool, error) {
|
||||||
tokenName, err := ctx.GetStub().GetState(nameKey)
|
tokenName, err := ctx.GetStub().GetState(nameKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -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)) {
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -473,7 +473,7 @@ class TokenERC20Contract extends Contract {
|
||||||
return clientAccountID;
|
return clientAccountID;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Checks that contract options have been already initialized
|
// Checks that contract options have been already initialized
|
||||||
async CheckInitialized(ctx){
|
async CheckInitialized(ctx){
|
||||||
const nameBytes = await ctx.stub.getState(nameKey);
|
const nameBytes = await ctx.stub.getState(nameKey);
|
||||||
if (!nameBytes || nameBytes.length === 0) {
|
if (!nameBytes || nameBytes.length === 0) {
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
@ -775,7 +775,7 @@ func (c *TokenERC721Contract) ClientAccountID(ctx contractapi.TransactionContext
|
||||||
return clientAccount, nil
|
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) {
|
func checkInitialized(ctx contractapi.TransactionContextInterface) (bool, error) {
|
||||||
tokenName, err := ctx.GetStub().GetState(nameKey)
|
tokenName, err := ctx.GetStub().GetState(nameKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -382,7 +382,7 @@ class TokenERC721Contract extends Contract {
|
||||||
* @returns {Boolean} Return whether the burn was successful or not
|
* @returns {Boolean} Return whether the burn was successful or not
|
||||||
*/
|
*/
|
||||||
async Burn(ctx, tokenId) {
|
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);
|
await this.CheckInitialized(ctx);
|
||||||
|
|
||||||
const owner = ctx.clientIdentity.getID();
|
const owner = ctx.clientIdentity.getID();
|
||||||
|
|
@ -432,7 +432,7 @@ class TokenERC721Contract extends Contract {
|
||||||
* @returns {Number} Returns the account balance
|
* @returns {Number} Returns the account balance
|
||||||
*/
|
*/
|
||||||
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
|
||||||
|
|
@ -444,7 +444,7 @@ class TokenERC721Contract extends Contract {
|
||||||
// In this implementation, the client account ID is the clientId itself.
|
// 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
|
// 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
|
||||||
|
|
@ -452,7 +452,7 @@ class TokenERC721Contract extends Contract {
|
||||||
return clientAccountID;
|
return clientAccountID;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Checks that contract options have been already initialized
|
// Checks that contract options have been already initialized
|
||||||
async CheckInitialized(ctx){
|
async CheckInitialized(ctx){
|
||||||
const nameBytes = await ctx.stub.getState(nameKey);
|
const nameBytes = await ctx.stub.getState(nameKey);
|
||||||
if (!nameBytes || nameBytes.length === 0) {
|
if (!nameBytes || nameBytes.length === 0) {
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ const totalSupplyKey = "totalSupply"
|
||||||
// Mint creates a new unspent transaction output (UTXO) owned by the minter
|
// Mint creates a new unspent transaction output (UTXO) owned by the minter
|
||||||
func (s *SmartContract) Mint(ctx contractapi.TransactionContextInterface, amount int) (*UTXO, error) {
|
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)
|
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)
|
||||||
|
|
@ -77,7 +77,7 @@ func (s *SmartContract) Mint(ctx contractapi.TransactionContextInterface, amount
|
||||||
// Transfer transfers UTXOs containing tokens from client to recipient(s)
|
// Transfer transfers UTXOs containing tokens from client to recipient(s)
|
||||||
func (s *SmartContract) Transfer(ctx contractapi.TransactionContextInterface, utxoInputKeys []string, utxoOutputs []UTXO) ([]UTXO, error) {
|
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)
|
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)
|
||||||
|
|
@ -181,7 +181,7 @@ func (s *SmartContract) Transfer(ctx contractapi.TransactionContextInterface, ut
|
||||||
// ClientUTXOs returns all UTXOs owned by the calling client
|
// ClientUTXOs returns all UTXOs owned by the calling client
|
||||||
func (s *SmartContract) ClientUTXOs(ctx contractapi.TransactionContextInterface) ([]*UTXO, error) {
|
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)
|
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)
|
||||||
|
|
@ -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
|
// 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) {
|
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)
|
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)
|
||||||
|
|
@ -266,7 +266,7 @@ func (s *SmartContract) ClientID(ctx contractapi.TransactionContextInterface) (s
|
||||||
|
|
||||||
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)
|
||||||
|
|
@ -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)
|
||||||
|
|
@ -319,7 +319,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)
|
||||||
|
|
@ -343,7 +343,7 @@ func (s *SmartContract) Initialize(ctx contractapi.TransactionContextInterface,
|
||||||
return true, nil
|
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) {
|
func checkInitialized(ctx contractapi.TransactionContextInterface) (bool, error) {
|
||||||
tokenName, err := ctx.GetStub().GetState(nameKey)
|
tokenName, err := ctx.GetStub().GetState(nameKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue