Skip to content

Commit

Permalink
Merge pull request tqtezos#34 from tqtezos/lambdahands/server-config-…
Browse files Browse the repository at this point in the history
…updates

feat: Update server with new NFT contract and config
  • Loading branch information
lambdahands authored Aug 31, 2020
2 parents 4ff9edd + 0e3ab49 commit 8fa2dbd
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 107 deletions.
72 changes: 0 additions & 72 deletions bin/originate-fa2-nft-contracts

This file was deleted.

6 changes: 3 additions & 3 deletions config/minter.sandbox.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"rpc": "http://localhost:20000",
"admin": {
"address": "tz1YPSCGWXwBdTncK2aCctSZAXWvGsGwVJqU",
"secret": "edsk3RFgDiCt7tWB2oe96w1eRw72iYiiqZPLu9nnEY23MYRp2d8Kkx"
"address": "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb",
"secret": "edskRpm2mUhvoUjHjXgMoDRxMKhtKfww1ixmWiHCWhHuMEEbGzdnz8Ks4vgarKDtxok7HmrEo1JzkXkdkvyw7Rtw6BNtSd7MJ7"
},
"contracts": {
"nft": "KT1HpTpGoktbMf9BFg5kgaCQR7uGw2AVabm5"
"nft": "KT1FVT95brPwbuWb6epuqU95hjzwyz2oqdz1"
}
}
25 changes: 11 additions & 14 deletions contracts/bin/fa2_multi_nft_asset.tz
Original file line number Diff line number Diff line change
Expand Up @@ -136,29 +136,29 @@
PAIR ;
PAIR ;
DUP ;
CAR ;
CDR ;
SWAP ;
DUP ;
DUG 2 ;
CAR ;
CDR ;
DIG 2 ;
CAR ;
CAR ;
IF_NONE
{ SWAP ; DROP }
{ SWAP ;
{ DROP }
{ DIG 2 ;
DUP ;
DUG 2 ;
DIG 3 ;
DUG 3 ;
DIG 2 ;
DUP ;
DUG 4 ;
DUG 3 ;
GET ;
IF_NONE
{ DROP 3 ; DIG 4 ; DUP ; DUG 5 ; FAILWITH }
{ COMPARE ;
EQ ;
IF { SWAP ; NONE address ; SWAP ; UPDATE }
IF { NONE address ; SWAP ; UPDATE }
{ DROP 2 ; DIG 4 ; DUP ; DUG 5 ; FAILWITH } } } ;
SWAP ;
DUP ;
Expand All @@ -185,12 +185,10 @@
DROP ;
DIG 2 ;
DROP ;
NIL operation ;
DUG 2 ;
DIP { DUP ; CDR ; SWAP ; CAR ; CDR } ;
PAIR ;
PAIR ;
SWAP ;
NIL operation ;
PAIR } ;
SWAP ;
APPLY ;
Expand Down Expand Up @@ -637,14 +635,13 @@
CONS ;
PAIR } } ;
DUP ;
CAR ;
NONE address ;
PAIR ;
SWAP ;
CDR ;
LAMBDA (pair address (big_map (pair address address) unit)) unit { DROP ; UNIT } ;
NIL (pair (option address) (list (pair (pair nat (option address)) nat))) ;
DIG 3 ;
CAR ;
NONE address ;
PAIR ;
CONS ;
PAIR ;
PAIR ;
Expand Down
1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"apollo-server-express": "^2.9.9",
"axios": "^0.19.0",
"bcrypt": "^3.0.7",
"bignumber.js": "^9.0.0",
"concurrently": "^5.0.0",
"configstore": "^5.0.1",
"cookie-parser": "^1.4.4",
Expand Down
10 changes: 3 additions & 7 deletions server/src/components/contract_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,22 @@ import Configstore from 'configstore';
import path from 'path';
import { Contract, TezosToolkit } from '@taquito/taquito';

const CONFIG_NAME = 'contract-config.json';
const TZ_NETWORK = process.env.TZ_NETWORK || 'sandbox';
const CONFIG_NAME = `minter.${TZ_NETWORK}.json`;
const CONFIG_PATH = path.join(__dirname, '../../config/', CONFIG_NAME);

const configStore = new Configstore('', {}, { configPath: CONFIG_PATH });

export interface ContractStore {
minterContract(): Promise<Contract>;
nftContract(): Promise<Contract>;
}

export default async function buildContractStore(
tzClient: TezosToolkit
): Promise<ContractStore> {
return {
minterContract() {
const minterContractAddress = configStore.get('minter_contract');
return tzClient.contract.at(minterContractAddress);
},
nftContract() {
const nftContractAddress = configStore.get('nft_contract');
const nftContractAddress = configStore.get('contracts.nft');
return tzClient.contract.at(nftContractAddress);
}
};
Expand Down
25 changes: 14 additions & 11 deletions server/src/resolvers/mutations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { MichelsonMap } from '@taquito/taquito';
import PublishedOperation from '../../models/published_operation';
import { TransactionOperation } from '@taquito/taquito/dist/types/operations/transaction-operation';
import { Context } from '../../components/context';
import { BigNumber } from 'bignumber.js';

async function confirmOperation(
{ db, pubsub, tzClient }: Context,
Expand All @@ -20,24 +21,26 @@ const Mutation: MutationResolvers = {
async createNonFungibleToken(_parent, args, ctx) {
const { db, contractStore } = ctx;
const nftContract = await contractStore.nftContract();
const minterContract = await contractStore.minterContract();
const nftStorage = await nftContract.storage<any>();
const adminAddress = await ctx.tzClient.signer.publicKeyHash();

const params = [
{
symbol: args.symbol,
name: args.name,
owner: adminAddress,
extras: new MichelsonMap({
prim: 'map',
args: [{ prim: 'string' }, { prim: 'string' }]
})
metadata: {
token_id: nftStorage.assets.next_token_id,
symbol: args.symbol,
name: args.name,
decimals: new BigNumber(0),
extras: new MichelsonMap({
prim: 'map',
args: [{ prim: 'string' }, { prim: 'string' }]
})
},
owner: adminAddress
}
];

const operation = await minterContract.methods
.mint(nftContract.address, params)
.send();
const operation = await nftContract.methods.mint(params).send();

await PublishedOperation.create(db, {
hash: operation.hash,
Expand Down

0 comments on commit 8fa2dbd

Please sign in to comment.