-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'beta' into fix/lint-project
- Loading branch information
Showing
23 changed files
with
1,479 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,94 @@ | ||
import { SubModule } from './SubModule'; | ||
import { PolymathError } from '../../PolymathError'; | ||
import { ErrorCode } from '../../types'; | ||
import { SetDocument } from '../../procedures/SetDocument'; | ||
import { RemoveDocument } from '../../procedures/RemoveDocument'; | ||
|
||
export class Documents extends SubModule {} | ||
interface Document { | ||
name: string; | ||
documentUri: string; | ||
documentHash: string; | ||
updatedAt: Date; | ||
} | ||
|
||
export class Documents extends SubModule { | ||
/** | ||
* Attach a new document to the contract, or update the URI or hash of an existing attached document | ||
* @param name Name of the document. It should be unique always | ||
* @param uri Off-chain uri of the document from where it is accessible to investors/advisors to read. | ||
* @param documentHash hash (of the contents) of the document. | ||
*/ | ||
public async set(args: { name: string; uri: string; documentHash: string }) { | ||
const { symbol } = this.securityToken; | ||
|
||
const procedure = new SetDocument({ symbol, ...args }, this.context); | ||
|
||
return procedure.prepare(); | ||
} | ||
|
||
/** | ||
* Remove an existing document from the contract giving the name of the document. | ||
* @param name Name of the document. It should be unique always | ||
*/ | ||
public async remove(args: { name: string }) { | ||
const { symbol } = this.securityToken; | ||
|
||
const procedure = new RemoveDocument({ symbol, ...args }, this.context); | ||
|
||
return procedure.prepare(); | ||
} | ||
|
||
/** | ||
* Retrieve a specific document's data by name | ||
* @param name Unique name of the document | ||
*/ | ||
public getDocument = async (args: { name: string }): Promise<Document> => { | ||
const { | ||
context: { contractWrappers }, | ||
securityToken, | ||
} = this; | ||
|
||
const { symbol } = securityToken; | ||
let securityTokenInstance; | ||
|
||
try { | ||
securityTokenInstance = await contractWrappers.tokenFactory.getSecurityTokenInstanceFromTicker( | ||
symbol | ||
); | ||
} catch (err) { | ||
throw new PolymathError({ | ||
code: ErrorCode.FetcherValidationError, | ||
message: `There is no Security Token with symbol ${symbol}`, | ||
}); | ||
} | ||
|
||
const { documentTime: updatedAt, ...info } = await securityTokenInstance.getDocument(args); | ||
return { updatedAt, ...args, ...info }; | ||
}; | ||
|
||
/** | ||
* Retrieve an array of all the documents attached to the security token | ||
*/ | ||
public getAllDocuments = async (): Promise<Document[]> => { | ||
const { | ||
context: { contractWrappers }, | ||
securityToken, | ||
} = this; | ||
|
||
const { symbol } = securityToken; | ||
let securityTokenInstance; | ||
|
||
try { | ||
securityTokenInstance = await contractWrappers.tokenFactory.getSecurityTokenInstanceFromTicker( | ||
symbol | ||
); | ||
} catch (err) { | ||
throw new PolymathError({ | ||
code: ErrorCode.FetcherValidationError, | ||
message: `There is no Security Token with symbol ${symbol}`, | ||
}); | ||
} | ||
const documentList = await securityTokenInstance.getAllDocuments(); | ||
return Promise.all(documentList.map(docname => this.getDocument({ name: docname }))); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.