Skip to content

Commit

Permalink
Merge pull request #372 from LF-Decentralized-Trust-labs/ts-example
Browse files Browse the repository at this point in the history
Add basic TypeScript example app
  • Loading branch information
awrichar authored Nov 5, 2024
2 parents c09aed1 + 7bcf17e commit ec27a8b
Show file tree
Hide file tree
Showing 35 changed files with 2,058 additions and 12 deletions.
5 changes: 5 additions & 0 deletions core/go/internal/txmgr/prepared_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/kaleido-io/paladin/toolkit/pkg/query"
"github.com/kaleido-io/paladin/toolkit/pkg/tktypes"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)

// DB persisted record for a prepared transaction
Expand Down Expand Up @@ -135,6 +136,10 @@ func (tm *txManager) WritePreparedTransactions(ctx context.Context, dbTX *gorm.D

if len(preparedTxInserts) > 0 {
err = dbTX.WithContext(ctx).
Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "id"}},
DoNothing: true, // immutable
}).
Create(preparedTxInserts).
Error
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ record TransactionExternalCall(
@JsonProperty
Address contractAddress,
@JsonProperty
byte[] encodedCall
JsonHex.Bytes encodedCall
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ void testBond() throws Exception {
var bondSubscription = BondSubscriptionHelper.deploy(aliceCustodianInstance, alice, new HashMap<>() {{
put("bondAddress_", notoBond.address());
put("units_", 1000);
put("custodian_", custodianAddress);
}});

// Prepare the bond transfer (requires 2 calls to prepare, as the Noto transaction spawns a Pente transaction to wrap it)
Expand Down Expand Up @@ -258,7 +259,7 @@ void testBond() throws Exception {
// so that it requires approval.

// Alice receives full bond distribution
bondSubscription.distribute(alice, 1000);
bondSubscription.distribute(bondCustodian, 1000);

// TODO: figure out how to test negative cases (such as when Pente reverts due to a non-allowed investor)

Expand Down
3 changes: 3 additions & 0 deletions example/bond/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
build/
src/abis/*.json
13 changes: 13 additions & 0 deletions example/bond/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Run",
"runtimeExecutable": "npm",
"args": ["run", "start"],
"request": "launch",
"type": "node",
"outputCapture": "std"
}
]
}
24 changes: 24 additions & 0 deletions example/bond/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Example: Bond Issuance

This example demonstrates a bond issuance scenario on Paladin. It leverages a combination of Noto tokens and
Pente private smart contracts in order to control visibility of various aspects of the bond issuance process.

## Running

Requires a local Paladin cluster running on `localhost:31548` and `localhost:31648`.

Compile [Solidity contracts](../../solidity):

```shell
cd ../../solidity
npm install
npm run compile
```

Run example:

```shell
npm install
npm run abi
npm run start
```
219 changes: 219 additions & 0 deletions example/bond/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions example/bond/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "paladin-example-bond",
"version": "0.0.1",
"description": "",
"main": "build/index.js",
"scripts": {
"build": "tsc",
"start": "ts-node ./src/index.ts",
"start:prod": "node ./build/index.js",
"abi": "node scripts/abi.mjs"
},
"author": "",
"license": "Apache-2.0",
"devDependencies": {
"@types/node": "^22.8.7",
"copy-file": "^11.0.0",
"typescript": "^5.6.3"
},
"dependencies": {
"ethers": "^6.13.4",
"paladin-sdk": "file:../../sdk/typescript",
"uuid": "^11.0.2"
}
}
26 changes: 26 additions & 0 deletions example/bond/scripts/abi.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { copyFile } from "copy-file";

await copyFile(
"../../solidity/artifacts/contracts/private/BondSubscription.sol/BondSubscription.json",
"src/abis/BondSubscription.json"
);

await copyFile(
"../../solidity/artifacts/contracts/private/BondTracker.sol/BondTracker.json",
"src/abis/BondTracker.json"
);

await copyFile(
"../../solidity/artifacts/contracts/private/InvestorRegistry.sol/InvestorRegistry.json",
"src/abis/InvestorRegistry.json"
);

await copyFile(
"../../solidity/artifacts/contracts/shared/BondTrackerPublic.sol/BondTrackerPublic.json",
"src/abis/BondTrackerPublic.json"
);

await copyFile(
"../../solidity/artifacts/contracts/domains/pente/PentePrivacyGroup.sol/PentePrivacyGroup.json",
"src/abis/PentePrivacyGroup.json"
);
1 change: 1 addition & 0 deletions example/bond/src/abis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Smart contract ABIs will be copied here by `npm run abi`.
Loading

0 comments on commit ec27a8b

Please sign in to comment.