Skip to content
This repository has been archived by the owner on Feb 18, 2021. It is now read-only.

Commit

Permalink
Merge pull request #44 from charleenfei/feat/nft_mint
Browse files Browse the repository at this point in the history
Tinlake MintNFT Updates
  • Loading branch information
charleenfei authored Sep 30, 2019
2 parents 88efaf6 + d7a3095 commit be5e52d
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 69 deletions.
3 changes: 2 additions & 1 deletion dist/Tinlake.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ interface ethI {
contract: (arg0: any) => {
at: (arg0: any) => void;
};
abi: any;
}
export declare type Address = string;
export interface Loan {
Expand Down Expand Up @@ -110,7 +111,7 @@ export declare class Tinlake {
/**
* @param owner Owner of the new NFT
*/
mintNFT: (owner: string, tokenId: string) => Promise<unknown>;
mintNFT: (owner: string, tokenId: string, ref: string, amount: string, asset: string) => Promise<unknown>;
/**
* @param owner Owner of the created loan
*/
Expand Down
92 changes: 67 additions & 25 deletions dist/Tinlake.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -27857,25 +27857,6 @@ var contractAbiNft = [
stateMutability: "nonpayable",
type: "function"
},
{
constant: false,
inputs: [
{
name: "usr",
type: "address"
},
{
name: "tkn",
type: "uint256"
}
],
name: "mint",
outputs: [
],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: false,
inputs: [
Expand Down Expand Up @@ -28017,6 +27998,37 @@ var contractAbiNft = [
stateMutability: "view",
type: "function"
},
{
constant: false,
inputs: [
{
name: "usr",
type: "address"
},
{
name: "tkn",
type: "uint256"
},
{
name: "ref",
type: "string"
},
{
name: "amount",
type: "uint256"
},
{
name: "asset",
type: "string"
}
],
name: "mint",
outputs: [
],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: true,
inputs: [
Expand All @@ -28040,6 +28052,37 @@ var contractAbiNft = [
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
{
name: "",
type: "uint256"
}
],
name: "data",
outputs: [
{
name: "reference_id",
type: "string"
},
{
name: "amount",
type: "uint256"
},
{
name: "asset_type",
type: "string"
},
{
name: "borrower",
type: "address"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
inputs: [
],
Expand Down Expand Up @@ -34723,15 +34766,14 @@ var Tinlake = /** @class */ (function () {
/**
* @param owner Owner of the new NFT
*/
this.mintNFT = function (owner, tokenId) { return __awaiter(_this, void 0, void 0, function () {
var tkn, txHash;
this.mintNFT = function (owner, tokenId, ref, amount, asset) { return __awaiter(_this, void 0, void 0, function () {
var txHash;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
tkn = abiCoder$1.encodeParameter('uint', tokenId);
return [4 /*yield*/, this.contracts.nft.mint(owner, tkn, this.ethConfig)];
case 0: return [4 /*yield*/, executeAndRetry(this.contracts.nft.mint, [owner, tokenId, ref, amount, asset, this.ethConfig])];
case 1:
txHash = _a.sent();
console.log("[NFT.mint] txHash: " + txHash);
return [2 /*return*/, waitAndReturnEvents(this.eth, txHash, this.contracts['nft'].abi, this.transactionTimeout)];
}
});
Expand Down Expand Up @@ -35017,7 +35059,7 @@ function executeAndRetry(f, args) {
return [2 /*return*/, result];
case 2:
e_1 = _a.sent();
// using error message, since error code -32603 is not unique enough
// using error message, since error code -32603 is not unique enough
// todo introduce retry limit
if (e_1 && e_1.message && (e_1.message.indexOf("Cannot read property 'number' of null") !== -1 ||
e_1.message.indexOf('error with payload') !== -1)) {
Expand Down
92 changes: 67 additions & 25 deletions dist/Tinlake.js
Original file line number Diff line number Diff line change
Expand Up @@ -27863,25 +27863,6 @@ var contractAbiNft = [
stateMutability: "nonpayable",
type: "function"
},
{
constant: false,
inputs: [
{
name: "usr",
type: "address"
},
{
name: "tkn",
type: "uint256"
}
],
name: "mint",
outputs: [
],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: false,
inputs: [
Expand Down Expand Up @@ -28023,6 +28004,37 @@ var contractAbiNft = [
stateMutability: "view",
type: "function"
},
{
constant: false,
inputs: [
{
name: "usr",
type: "address"
},
{
name: "tkn",
type: "uint256"
},
{
name: "ref",
type: "string"
},
{
name: "amount",
type: "uint256"
},
{
name: "asset",
type: "string"
}
],
name: "mint",
outputs: [
],
payable: false,
stateMutability: "nonpayable",
type: "function"
},
{
constant: true,
inputs: [
Expand All @@ -28046,6 +28058,37 @@ var contractAbiNft = [
stateMutability: "view",
type: "function"
},
{
constant: true,
inputs: [
{
name: "",
type: "uint256"
}
],
name: "data",
outputs: [
{
name: "reference_id",
type: "string"
},
{
name: "amount",
type: "uint256"
},
{
name: "asset_type",
type: "string"
},
{
name: "borrower",
type: "address"
}
],
payable: false,
stateMutability: "view",
type: "function"
},
{
inputs: [
],
Expand Down Expand Up @@ -34729,15 +34772,14 @@ var Tinlake = /** @class */ (function () {
/**
* @param owner Owner of the new NFT
*/
this.mintNFT = function (owner, tokenId) { return __awaiter(_this, void 0, void 0, function () {
var tkn, txHash;
this.mintNFT = function (owner, tokenId, ref, amount, asset) { return __awaiter(_this, void 0, void 0, function () {
var txHash;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
tkn = abiCoder$1.encodeParameter('uint', tokenId);
return [4 /*yield*/, this.contracts.nft.mint(owner, tkn, this.ethConfig)];
case 0: return [4 /*yield*/, executeAndRetry(this.contracts.nft.mint, [owner, tokenId, ref, amount, asset, this.ethConfig])];
case 1:
txHash = _a.sent();
console.log("[NFT.mint] txHash: " + txHash);
return [2 /*return*/, waitAndReturnEvents(this.eth, txHash, this.contracts['nft'].abi, this.transactionTimeout)];
}
});
Expand Down Expand Up @@ -35023,7 +35065,7 @@ function executeAndRetry(f, args) {
return [2 /*return*/, result];
case 2:
e_1 = _a.sent();
// using error message, since error code -32603 is not unique enough
// using error message, since error code -32603 is not unique enough
// todo introduce retry limit
if (e_1 && e_1.message && (e_1.message.indexOf("Cannot read property 'number' of null") !== -1 ||
e_1.message.indexOf('error with payload') !== -1)) {
Expand Down
4 changes: 2 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export default {
],
external: [
// ...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
...Object.keys(pkg.peerDependencies || {})
],
plugins: [
resolve(),
resolve({preferBuiltins: true}),
commonjs(),
json({
// All JSON files will be parsed by default,
Expand Down
24 changes: 13 additions & 11 deletions src/Tinlake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const abiCoder = new AbiCoder();
import BN from 'bn.js';
import { sha3 } from 'web3-utils';


import contractAbiNft from './abi/test/SimpleNFT.abi.json';
import contractAbiTitle from './abi/Title.abi.json';
import contractAbiCurrency from './abi/test/SimpleToken.abi.json';
Expand Down Expand Up @@ -91,6 +92,7 @@ interface ethI {
getTransactionReceipt: (arg0: any, arg1: (err: any, receipt: any) => void) => void;
getTransactionByHash: (arg0: any, arg1: (err: any, tx: any) => void) => void;
contract: (arg0: any) => { at: (arg0: any) => void };
abi: any;
}

interface Events {
Expand Down Expand Up @@ -269,25 +271,26 @@ export class Tinlake {
/**
* @param owner Owner of the new NFT
*/
mintNFT = async (owner: string, tokenId: string) => {
const tkn = abiCoder.encodeParameter('uint', tokenId)
const txHash = await this.contracts.nft.mint(owner, tkn, this.ethConfig);
mintNFT = async (owner: string, tokenId: string, ref: string, amount: string, asset:string) => {
const txHash = await executeAndRetry(this.contracts.nft.mint, [owner, tokenId, ref, amount, asset, this.ethConfig]);
console.log(`[NFT.mint] txHash: ${txHash}`);
return waitAndReturnEvents(this.eth, txHash, this.contracts['nft'].abi, this.transactionTimeout);
}
};

/**
* @param owner Owner of the created loan
*/
adminAdmit = async (registry: string, nft: string, principal: string, owner: string) => {
const txHash = await executeAndRetry(this.contracts.admit.admit, [registry, nft, principal, owner, this.ethConfig])
console.log(`[Admit.admit] txHash: ${txHash}`);
return waitAndReturnEvents(this.eth, txHash, this.contracts['nft'].abi, this.transactionTimeout);
return waitAndReturnEvents(this.eth, txHash, this.contracts['nft'].abi, this.transactionTimeout);
}

adminAppraise = async (loanID: string, appraisal: string) => {
const txHash = await executeAndRetry(this.contracts.appraiser.file, [loanID, appraisal, this.ethConfig]);
console.log(`[Appraisal.file] txHash: ${txHash}`);
return waitAndReturnEvents(this.eth, txHash, this.contracts['nft'].abi, this.transactionTimeout);

}

getAppraisal = async (loanID: string) => {
Expand All @@ -308,8 +311,8 @@ export class Tinlake {
* @param wad Amount which should be repaid
* @param usr Address that receives the NFT
*/
repay = async (loanId: string, wad: string, usr: string)=> {
const txHash = await executeAndRetry(this.contracts.reception.repay, [loanId, wad, usr, this.ethConfig])
repay = async (loanId: string, wad: string, usr: string) => {
const txHash = await executeAndRetry(this.contracts.reception.repay, [loanId, wad, usr, this.ethConfig])
console.log(`[Reception.repay] txHash: ${txHash}`);
return waitAndReturnEvents(this.eth, txHash, this.contracts['reception'].abi, this.transactionTimeout);
}
Expand Down Expand Up @@ -365,8 +368,7 @@ export class Tinlake {
* using initFee
* @param owner Owner of the created loan
*/
whitelist = async (registry: Address, nft: string, principal: string, appraisal: string,
fee: string, owner: string) => {
whitelist = async (registry: Address, nft: string, principal: string, appraisal: string, fee: string, owner: string) => {
const txHash = await executeAndRetry(this.contracts.admin.whitelist, [registry, nft, principal, appraisal, fee, owner, this.ethConfig]);
console.log(`[Admin.whitelist] txHash: ${txHash}`);
return waitAndReturnEvents(this.eth, txHash, this.contracts['nft'].abi, this.transactionTimeout);
Expand Down Expand Up @@ -404,7 +406,7 @@ async function executeAndRetry (f: Function, args: Array<any> = []) : Promise<an
const result = await f(...args);
return result;
} catch (e) {
// using error message, since error code -32603 is not unique enough
// using error message, since error code -32603 is not unique enough
// todo introduce retry limit
if (e && e.message && (e.message.indexOf("Cannot read property 'number' of null") !== -1 ||
e.message.indexOf('error with payload') !== -1)) {
Expand Down
2 changes: 1 addition & 1 deletion src/abi/test/SimpleNFT.abi.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"constant":true,"inputs":[{"name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"from","type":"address"},{"name":"to","type":"address"},{"name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"usr","type":"address"},{"name":"tkn","type":"uint256"}],"name":"mint","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"from","type":"address"},{"name":"to","type":"address"},{"name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"from","type":"address"},{"name":"to","type":"address"},{"name":"tokenId","type":"uint256"},{"name":"_data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"},{"name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":true,"name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"approved","type":"address"},{"indexed":true,"name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"operator","type":"address"},{"indexed":false,"name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"}]
[{"constant":true,"inputs":[{"name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"tokenId","type":"uint256"}],"name":"getApproved","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"tokenId","type":"uint256"}],"name":"approve","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"from","type":"address"},{"name":"to","type":"address"},{"name":"tokenId","type":"uint256"}],"name":"transferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"from","type":"address"},{"name":"to","type":"address"},{"name":"tokenId","type":"uint256"}],"name":"safeTransferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"from","type":"address"},{"name":"to","type":"address"},{"name":"tokenId","type":"uint256"},{"name":"_data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"usr","type":"address"},{"name":"tkn","type":"uint256"},{"name":"ref","type":"string"},{"name":"amount","type":"uint256"},{"name":"asset","type":"string"}],"name":"mint","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"},{"name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"data","outputs":[{"name":"reference_id","type":"string"},{"name":"amount","type":"uint256"},{"name":"asset_type","type":"string"},{"name":"borrower","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":true,"name":"tokenId","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"approved","type":"address"},{"indexed":true,"name":"tokenId","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"operator","type":"address"},{"indexed":false,"name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"}]
8 changes: 4 additions & 4 deletions src/declarations.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
declare module '*.abi' {
const value: any
export default value
const value: any;
export default value;
}

declare module 'ethjs'
declare module 'web3-utils'
declare module 'ethjs';
declare module 'web3-utils';

0 comments on commit be5e52d

Please sign in to comment.