1+ const { TezosToolkit, MichelsonMap } = require ( '@taquito/taquito' )
2+ const serverless = require ( 'serverless-http' )
3+ const express = require ( 'express' )
4+ const cors = require ( 'cors' )
5+ const app = express ( )
6+
7+ const Tezos = new TezosToolkit ( 'https://api.tez.ie/rpc/mainnet' )
8+ const mfp_mainnet = 'KT1Q72pNNiCnBamwttWvXGE9N2yuz6c7guSD'
9+ const objkts_mainnet = 'KT1SiUb8CDJVDTxHkMa7B5ZQKr8oCDjHznFD'
10+ const ipfs = 'ipfs://'
11+
12+ app . use ( express . json ( ) )
13+ app . use ( cors ( { origin : '*' } ) )
14+
15+ app . get ( '/' , ( req , res ) => res . json ( { result :200 } ) )
16+
17+ app . post ( '/api/v1/mfp/originate' , ( req , res ) => {
18+
19+ Tezos . contract
20+ . at ( mfp_mainnet )
21+ . then ( c => res . json ( { result : c . methods . originate_hicetnuncDAO ( req . body . tz , req . body . goal , req . body . metadata ) . toTransferParams ( ) } ) )
22+
23+ } )
24+
25+ app . post ( '/api/v1/mfp/withdraw' , ( req , res ) => {
26+ //Tezos.contract.at(kt).then( c => console.log(c.parameterSchema.ExtractSignatures()))
27+ Tezos . contract . at ( req . body . kt ) . then ( c => res . json ( { result : c . methods . withdraw ( req . body . tz , req . body . amount ) . toTransferParams ( ) } ) )
28+ } )
29+
30+ app . post ( '/api/v1/mfp/update_metadata' , ( req , res ) => {
31+ Tezos . contract . at ( req . body . kt ) . then ( c => res . json ( { result : c . methods . update_meta ( req . body . metadata ) . toTransferParams ( ) } ) )
32+ } )
33+
34+ app . post ( '/api/v1/mfp/contribute' , ( req , res ) => {
35+ console . log ( req . body )
36+ Tezos . contract . at ( req . body . kt ) . then ( c => res . json ( { result : c . methods . contribute ( null ) . toTransferParams ( { amount : parseInt ( req . body . amount ) , mutez : true } ) } ) )
37+ } )
38+
39+ app . post ( '/api/v1/mfp/update_adm' , ( req , res ) => {
40+ Tezos . contract . at ( req . body . kt ) . then ( c => res . json ( { result : c . methods . update_admin ( req . body . tz ) . toTransferParams ( ) } ) )
41+ } )
42+
43+ app . post ( '/api/v1/mfp/set_baker' , ( req , res ) => {
44+ Tezos . contract . at ( req . body . kt ) . then ( c => res . json ( { result : c . methods . set_baker ( req . body . tz ) . toTransferParams ( ) } ) )
45+ } )
46+
47+ app . post ( '/api/v1/objkts/mint' , ( req , res ) => {
48+ console . log ( { '' : ( ipfs + req . body . cid ) . split ( "" ) . reduce ( ( hex , c ) => hex += c . charCodeAt ( 0 ) . toString ( 16 ) . padStart ( 2 , "0" ) , "" ) } )
49+ Tezos . contract . at ( objkts_mainnet ) . then ( c => res . json ( { result : c . methods . default ( req . body . tz , req . body . amount , MichelsonMap . fromLiteral ( { '' : ( ipfs + req . body . cid ) . split ( "" ) . reduce ( ( hex , c ) => hex += c . charCodeAt ( 0 ) . toString ( 16 ) . padStart ( 2 , "0" ) , "" ) } ) ) . toTransferParams ( ) } ) )
50+ } )
51+
52+ //app.listen(3001, () => console.log(`Listening on: 3001`));
53+ module . exports . handler = serverless ( app )
0 commit comments