@vostokplatform/voting-contract-api
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -1,11 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DEFAULTS = { | ||
statusResponseTimeout: 100000, | ||
isWaitTransitionMining: true, | ||
}; | ||
var weVotingContract_1 = require("./modules/voting/weVotingContract"); | ||
exports.WeVotingContract = weVotingContract_1.WeVotingContract; | ||
var rtVotingContract_1 = require("./modules/voting/rtVotingContract"); | ||
exports.RtVotingContract = rtVotingContract_1.RtVotingContract; | ||
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("moment"),require("@vostokplatform/waves-api"));else if("function"==typeof define&&define.amd)define(["moment","@vostokplatform/waves-api"],e);else{var i="object"==typeof exports?e(require("moment"),require("@vostokplatform/waves-api")):e(t.moment,t["@vostokplatform/waves-api"]);for(var n in i)("object"==typeof exports?exports:t)[n]=i[n]}}(this,(function(t,e){return function(t){var e={};function i(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(n,r,function(e){return t[e]}.bind(null,r));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=0)}([function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.DEFAULTS=void 0,e.DEFAULTS={statusResponseTimeout:1e5,isWaitTransitionMining:!0};var n=i(3);Object.defineProperty(e,"WeVotingContract",{enumerable:!0,get:function(){return n.WeVotingContract}});var r=i(10);Object.defineProperty(e,"RtVotingContract",{enumerable:!0,get:function(){return r.RtVotingContract}})},function(t,e,i){"use strict";var n=this&&this.__awaiter||function(t,e,i,n){return new(i||(i=Promise))((function(r,a){function s(t){try{c(n.next(t))}catch(t){a(t)}}function o(t){try{c(n.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,o)}c((n=n.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.VotingContract=void 0;const r=i(4),a=i(5),s=i(0),o=i(9),c=i(2);e.VotingContract=class{constructor(t){this.initVoting=t=>n(this,void 0,void 0,(function*(){const{txParams:{fee:e,contractName:i,image:n,imageHash:r},contractParams:s}=t,o={senderPublicKey:this.keyPair.publicKey,timestamp:Date.now(),image:n,imageHash:r,contractName:i,params:Object.entries(s).map(a.convertToIParam),fee:e},c=yield this.weApi.API.Node.transactions.broadcastFromClientAddress("dockerCreateV2",o,this.keyPair);if(this.isWaitTransitionMining){const t=yield this.waitTransitionMining.waitMining(c.id);return Object.assign({data:c},t)}return{data:c,success:!0}})),this.createOperationParam=t=>({type:c.ParamType.string,key:"operation",value:t}),this.callDockerContract=(t,e)=>n(this,void 0,void 0,(function*(){const{txParams:{contractId:i,fee:n},contractParams:r}=e,s={senderPublicKey:this.keyPair.publicKey,authorPublicKey:this.keyPair.publicKey,contractId:i,timestamp:Date.now(),params:[t,...Object.entries(r).map(a.convertToIParam)],fee:n},o=yield this.weApi.API.Node.transactions.broadcastFromClientAddress("dockerCall",s,this.keyPair);if(this.isWaitTransitionMining){const t=yield this.waitTransitionMining.waitMining(o.id);return Object.assign({data:o},t)}return{data:o,success:!0}})),this.updateServerList=t=>this.callDockerContract(this.createOperationParam("updateServerList"),t),this.dkgRound=t=>this.callDockerContract(this.createOperationParam("dkgRound"),t),this.addMainKey=t=>this.callDockerContract(this.createOperationParam("addMainKey"),t),this.results=t=>this.callDockerContract(this.createOperationParam("results"),t),this.dkgCommit=t=>this.callDockerContract(this.createOperationParam("dkgCommit"),t),this.dkgScalar=t=>this.callDockerContract(this.createOperationParam("dkgScalar"),t),this.dkgShadows=t=>this.callDockerContract(this.createOperationParam("dkgShadows"),t),this.dkgComplaint=t=>this.callDockerContract(this.createOperationParam("dkgComplaint"),t),this.decryption=t=>this.callDockerContract(this.createOperationParam("decryption"),t);const{weApiConfig:e,fetchInstance:i,keyPair:u,statusResponseTimeout:l,isWaitTransitionMining:d}=Object.assign(Object.assign({},s.DEFAULTS),t);this.keyPair=u,this.isWaitTransitionMining=d,this.weApi=o.create({initialConfiguration:e,fetchInstance:i}),this.waitTransitionMining=new r.WaitTransitionMining(e.nodeAddress.replace(/\/$/,""),Math.floor(l/1e3),i)}}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.ParamType=void 0,function(t){t.string="string",t.integer="integer",t.boolean="boolean"}(e.ParamType||(e.ParamType={}))},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.WeVotingContract=void 0;const n=i(1);class r extends n.VotingContract{constructor(t){super(t),this.initiateVoting=t=>this.initVoting(t),this.vote=t=>this.callDockerContract(this.createOperationParam("vote"),t),this.updateAdminList=t=>this.callDockerContract(this.createOperationParam("updateAdminList"),t),this.addParticipants=t=>this.callDockerContract(this.createOperationParam("addParticipants"),t)}}e.WeVotingContract=r},function(t,e,i){"use strict";var n=this&&this.__awaiter||function(t,e,i,n){return new(i||(i=Promise))((function(r,a){function s(t){try{c(n.next(t))}catch(t){a(t)}}function o(t){try{c(n.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,o)}c((n=n.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.WaitTransitionMining=void 0;class r{constructor(){this.timeout=null,this.promiseResolve=null}wait(t){return new Promise(e=>{this.promiseResolve=e,this.timeout=setTimeout(()=>{e(!0)},1e3*t)})}cancel(){this.timeout&&clearTimeout(this.timeout),this.promiseResolve&&this.promiseResolve(!1)}}e.WaitTransitionMining=class{constructor(t,e,i){this.apiUrl=t,this.responseTimeout=e,this.fetchInstance=i,this.getTransactionStatus=t=>n(this,void 0,void 0,(function*(){try{const e=yield this.fetchInstance(`${this.apiUrl}/contracts/status/${t}`,{method:"GET"}),i=yield e.json();return{success:200===e.status&&Array.isArray(i)&&i.some(t=>"Success"===t.status),status:i}}catch(t){return t[0]&&t[0].error&&t[0].message?{success:!1,status:t}:{success:!1,status:{error:500,message:"can not process status request "+JSON.stringify(t)}}}}))}waitMining(t){let e,i=!1;const a=new r,s=new r,o=r=>n(this,void 0,void 0,(function*(){if(!(yield s.wait(r)))return e||{success:!1,status:{error:500,message:"request canceled"}};const n=yield this.getTransactionStatus(t);return e=n,i?e:n.success?(a.cancel(),i=!0,n):o(.5)}));return Promise.race([o(0),a.wait(this.responseTimeout).then(()=>(s.cancel(),i=!0,e||{success:!1,status:{error:500,message:"wait status timeout"}}))])}}},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.convertToIParam=void 0;const n=i(2),r=i(6);class a extends Error{constructor(t){super(`Error. Cannot map contract params. Unknown type for key: ${t}.`),this.name="MapContractParamsError"}}e.convertToIParam=t=>{const[e,i]=t;switch(typeof i){case"string":return{type:n.ParamType.string,key:e,value:i};case"number":return{type:n.ParamType.integer,key:e,value:i};case"object":return r.isDateInstance(i)?{type:n.ParamType.string,key:e,value:r.getDateString(i)}:Array.isArray(i)&&"docs"===e?{type:n.ParamType.string,key:e,value:JSON.stringify(i.map(t=>Object.assign(Object.assign({},t),{dateUpload:r.getDateString(t.dateUpload)})))}:{type:n.ParamType.string,key:e,value:JSON.stringify(i)};default:throw new a(e)}}},function(t,e,i){"use strict";var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.getDateString=e.isDateInstance=void 0;const r=n(i(7)),a=i(8);e.isDateInstance=function(t){return t instanceof Date&&!isNaN(t.valueOf())},e.getDateString=function(t){return r.default.utc(t).format(a.DateFormat)}},function(e,i){e.exports=t},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.DateFormat=void 0,e.DateFormat="DD-MM-YYYY HH:mm:ss"},function(t,i){t.exports=e},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.RtVotingContract=void 0;const n=i(1);class r extends n.VotingContract{constructor(t){super(t),this.initiateVoting=t=>this.initVoting(t),this.vote=t=>this.callDockerContract(this.createOperationParam("vote"),t),this.finishVoting=t=>this.callDockerContract(this.createOperationParam("finishVoting"),t)}}e.RtVotingContract=r}])})); | ||
//# sourceMappingURL=index.js.map |
@@ -9,3 +9,3 @@ import { VotingContract } from './votingContract'; | ||
vote: (params: RtVoteParams) => Promise<IModifiedWavesApiResponse>; | ||
finishVoting: (params: IDockerCallParams<{}, import("../../types/general").IDockerCallTxParams>) => Promise<IModifiedWavesApiResponse>; | ||
finishVoting: (params: IDockerCallParams<{}>) => Promise<IModifiedWavesApiResponse>; | ||
} |
@@ -56,2 +56,3 @@ import { IWavesConfig } from '@vostokplatform/waves-api/interfaces'; | ||
pollType: string; | ||
pollId: string; | ||
title: string; | ||
@@ -76,2 +77,3 @@ description?: string; | ||
pollType: string; | ||
pollId: string; | ||
bulletinHash: string; | ||
@@ -78,0 +80,0 @@ dimension: number[]; |
import { IStatusResponse } from '../types/wavesApi'; | ||
export declare const waitSeconds: (time: number) => Promise<unknown>; | ||
export declare class WaitTransitionMining { | ||
@@ -4,0 +3,0 @@ private readonly apiUrl; |
@@ -34,3 +34,3 @@ import { MAINNET_CONFIG } from '@vostokplatform/waves-api' | ||
statusResponseTimeout: 100000, | ||
isWaitTransitionMining: false, | ||
isWaitTransitionMining: true, | ||
weApiConfig, | ||
@@ -37,0 +37,0 @@ }) |
@@ -38,3 +38,3 @@ import { MAINNET_CONFIG } from '@vostokplatform/waves-api' | ||
fee: 0, | ||
contractId: '7MpBHYH46Ge976U8jQYF2ea4E348K7Dv5xH1FQ6imVjz', | ||
contractId: 'CLT1oAYUqHpCQHzbMoP9nmccpvWyDQ7ypcANUQsmQqu2a', | ||
}, | ||
@@ -41,0 +41,0 @@ contractParams: {}, |
{ | ||
"name": "@vostokplatform/voting-contract-api", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "", | ||
@@ -12,3 +12,4 @@ "main": "dist/index.js", | ||
"tsc": "npx tsc --noEmit", | ||
"test-ci": "npm i && npm run tslint && npm run tsc" | ||
"test": "jest --verbose", | ||
"test-ci": "npm i && npm run tslint && npm run tsc && npm run test" | ||
}, | ||
@@ -20,21 +21,54 @@ "keywords": [], | ||
"@types/isomorphic-fetch": "0.0.35", | ||
"@types/jest": "^26.0.10", | ||
"@types/node": "13.7.7", | ||
"@vostokplatform/api-token-refresher": "2.2.0", | ||
"@vostokplatform/waves-api": "1.3.6-RC2", | ||
"clean-webpack-plugin": "^3.0.0", | ||
"dotenv": "^8.2.0", | ||
"isomorphic-fetch": "2.2.1", | ||
"jest": "^26.4.0", | ||
"jest-fetch-mock": "^3.0.3", | ||
"moment": "2.24.0", | ||
"ts-jest": "^26.2.0", | ||
"ts-loader": "6.2.1", | ||
"ts-node": "^8.6.2", | ||
"tslint": "^6.1.2", | ||
"typescript": "^3.9.5", | ||
"tslint": "^6.1.2", | ||
"webpack": "4.42.0", | ||
"webpack-cli": "^3.3.11", | ||
"ts-loader": "6.2.1", | ||
"isomorphic-fetch": "2.2.1", | ||
"@vostokplatform/api-token-refresher": "2.2.0", | ||
"@vostokplatform/waves-api": "1.3.6-RC2", | ||
"moment": "2.24.0", | ||
"dotenv": "^8.2.0", | ||
"clean-webpack-plugin": "^3.0.0" | ||
"webpack-cli": "^3.3.11" | ||
}, | ||
"dependencies": {}, | ||
"peerDependencies": { | ||
"@vostokplatform/waves-api": "1.3.6-RC2", | ||
"moment": "2.24.0" | ||
}, | ||
"jest": { | ||
"testTimeout": 3000, | ||
"moduleFileExtensions": [ | ||
"js", | ||
"json", | ||
"ts" | ||
], | ||
"rootDir": "test", | ||
"testRegex": ".spec.ts$", | ||
"transform": { | ||
"^.+\\.(t|j)s$": "ts-jest" | ||
}, | ||
"coverageDirectory": "../coverage", | ||
"testEnvironment": "node", | ||
"coverageThreshold": { | ||
"global": { | ||
"branches": 50, | ||
"functions": 50, | ||
"lines": 50 | ||
} | ||
}, | ||
"coverageReporters": [ | ||
"text", | ||
"html" | ||
], | ||
"automock": false, | ||
"setupFiles": [ | ||
"./helpers/setupJest.ts" | ||
] | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 11 instances in 1 package
74122
1179
1
1
18
28
3