Cargo Callback Contracts

Cargo allows you to associate a Cargo callback contract to a newly created crate. These contracts adhere to a specific interface and certain methods within that contract will be called after certain events take place on the Cargo platform such as adding a vendor and minting a token. This allows you to extend the Cargo platform for your own personal use by using your own custom smart contracts.

Cargo uses the ERC-165 specification to define a standard interface. Your contract must adhere to the following interface:

CargoCallbackInterface.sol
interface CargoCallbackInterface {
function afterMint(address tokenAddress, uint mintedTokenId, address to) external;
function afterTransfer(address tokenAddress, uint tokenId, address from, address to) external;
function afterCreateVendor(uint256 vendorId, address vendorAddress) external;
function afterTokenContractCreated(address tokenContractAddress) external;
function afterBeneficiaryAdded(uint256 beneficiaryId, address beneficiaryAddress) external;
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

Here is an example callback contract that Cargo uses for internal tests:

contract CargoCallback is ERC165 {
constructor() public {
_registerInterface(
this.afterMint.selector ^
this.afterTransfer.selector ^
this.afterCreateVendor.selector ^
this.afterTokenContractCreated.selector ^
this.afterBeneficiaryAdded.selector
);
}
function calculateSelector() public pure returns (bytes4) {
return this.afterMint.selector ^
this.afterTransfer.selector ^
this.afterCreateVendor.selector ^
this.afterTokenContractCreated.selector ^
this.afterBeneficiaryAdded.selector;
}
mapping(string => bool) data;
function getData(string memory key) public view returns (bool) {
return data[key];
}
function afterMint(address tokenAddress, uint mintedTokenId, address to) external {
data["afterMint"] = true;
}
function afterTransfer(address tokenAddress, uint tokenId, address from, address to) external {
data["afterTransfer"] = true;
}
function afterCreateVendor(uint256 vendorId, address vendorAddress) external {
data["afterCreateVendor"] = true;
}
function afterTokenContractCreated(address tokenContractAddress) external {
data["afterTokenContractCreated"] = true;
}
function afterBeneficiaryAdded(uint256 beneficiaryId, address beneficiaryAddress) external {
data["afterBeneficiaryAdded"] = true;
}
}

As you can see the above contract extends an ERC165 contract. You can use the OpenZeppelin implementation. https://docs.openzeppelin.org/v2.3.0/api/introspection#erc165

Once you've created the contract you can create a new crate and associate the newly created contract with it by calling the Cargo JS createCrateWithCallbackContract method.