update to new CLR version, refine deployment script with better log output
This commit is contained in:
Generated
+431
-609
File diff suppressed because it is too large
Load Diff
+3
-4
@@ -13,7 +13,7 @@
|
||||
"copy-gui": "cp src/frontend/build/index.html gui",
|
||||
"webpack-gateway": "webpack --config webpack.gateway.js --progress && cp build/gateway/main.js gateway",
|
||||
"deploy": "node ./lib/Deploy.js",
|
||||
"github": "cp gateway/* ~/caisar.github.io && cd ~/caisar.github.io && git checkout master && git add -A && git commit -m \"update\" --allow-empty && git push origin master --force && git checkout main && git add -A && git commit -m \"update\" --allow-empty && git push origin main --force"
|
||||
"github": "cp gateway/index.html ~/caisar.github.io && cp gateway/main.js ~/caisar.github.io && cd ~/caisar.github.io && git checkout master && git add -A && git commit -m \"update\" --allow-empty && git push origin master --force && git checkout main && git add -A && git commit -m \"update\" --allow-empty && git push origin main --force"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
@@ -36,8 +36,7 @@
|
||||
"typescript": "^4.9.3",
|
||||
"url": "^0.11.0",
|
||||
"utf8": "^3.0.0",
|
||||
"webpack": "^5.75.0",
|
||||
"webpack-bundle-analyzer": "^4.7.0",
|
||||
"webpack-cli": "^5.0.0"
|
||||
"webpack": "^5.88.2",
|
||||
"webpack-cli": "^5.1.4"
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -11,9 +11,11 @@ const path = require('path');
|
||||
console.log("Getting html from "+htmlPath)
|
||||
const htmlBuf = await fs.readFile(htmlPath)
|
||||
const html = htmlBuf.toString('ascii')
|
||||
console.log(`Writing ${html.length} bytes to blockchain...`)
|
||||
const dataHash = await api.treeWrite(html, config.contractAddress, config.secret)
|
||||
await api.disconnect()
|
||||
console.log("Done. Your upload is at: ", dataHash);
|
||||
console.log("Building gateway ...")
|
||||
child_process.exec(`DATA_HASH=${dataHash} npm run webpack-gateway`, console.log)
|
||||
console.log("Building gateway...")
|
||||
child_process.exec(`DATA_HASH=${dataHash} npm run webpack-gateway`, ()=>{})
|
||||
console.log(`Success. You can now open the application under ${path.join(__dirname, '..', 'gateway', 'index.html')}`)
|
||||
})()
|
||||
@@ -1,17 +0,0 @@
|
||||
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
|
||||
# For additional information regarding the format and rule options, please see:
|
||||
# https://github.com/browserslist/browserslist#queries
|
||||
|
||||
# For the full list of supported browsers by the Angular framework, please see:
|
||||
# https://angular.io/guide/browser-support
|
||||
|
||||
# You can see what browsers were selected by your queries by running:
|
||||
# npx browserslist
|
||||
|
||||
last 1 Chrome version
|
||||
last 1 Firefox version
|
||||
last 2 Edge major versions
|
||||
last 2 Safari major versions
|
||||
last 2 iOS major versions
|
||||
Firefox ESR
|
||||
not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line.
|
||||
@@ -0,0 +1,16 @@
|
||||
# Editor configuration, see https://editorconfig.org
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.ts]
|
||||
quote_type = single
|
||||
|
||||
[*.md]
|
||||
max_line_length = off
|
||||
trim_trailing_whitespace = false
|
||||
@@ -0,0 +1,38 @@
|
||||
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
||||
|
||||
# Compiled output
|
||||
/dist
|
||||
/tmp
|
||||
/out-tsc
|
||||
/bazel-out
|
||||
|
||||
# Node
|
||||
/node_modules
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
|
||||
# IDEs and editors
|
||||
.idea/
|
||||
.project
|
||||
.classpath
|
||||
.c9/
|
||||
*.launch
|
||||
.settings/
|
||||
*.sublime-workspace
|
||||
|
||||
# Visual Studio Code
|
||||
.vscode
|
||||
.history
|
||||
|
||||
# Miscellaneous
|
||||
/.angular/cache
|
||||
.sass-cache/
|
||||
/connect.lock
|
||||
/coverage
|
||||
/libpeerconnection.log
|
||||
testem.log
|
||||
/typings
|
||||
|
||||
# System files
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
@@ -0,0 +1,27 @@
|
||||
# AngularClr
|
||||
|
||||
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 13.3.0.
|
||||
|
||||
## Development server
|
||||
|
||||
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The application will automatically reload if you change any of the source files.
|
||||
|
||||
## Code scaffolding
|
||||
|
||||
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
|
||||
|
||||
## Build
|
||||
|
||||
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory.
|
||||
|
||||
## Running unit tests
|
||||
|
||||
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
|
||||
|
||||
## Running end-to-end tests
|
||||
|
||||
Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities.
|
||||
|
||||
## Further help
|
||||
|
||||
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
|
||||
+24
-17
@@ -1,9 +1,12 @@
|
||||
{
|
||||
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
||||
"cli": {
|
||||
"analytics": false
|
||||
},
|
||||
"version": 1,
|
||||
"newProjectRoot": "projects",
|
||||
"projects": {
|
||||
"angular-cli": {
|
||||
"angular-clr": {
|
||||
"projectType": "application",
|
||||
"schematics": {
|
||||
"@schematics/angular:component": {
|
||||
@@ -20,29 +23,29 @@
|
||||
"build": {
|
||||
"builder": "@angular-devkit/build-angular:browser",
|
||||
"options": {
|
||||
"outputPath": "dist/angular-cli",
|
||||
"outputPath": "dist/angular-clr",
|
||||
"index": "src/index.html",
|
||||
"main": "src/main.ts",
|
||||
"polyfills": "src/polyfills.ts",
|
||||
"tsConfig": "tsconfig.app.json",
|
||||
"inlineStyleLanguage": "scss",
|
||||
"assets": ["src/favicon.ico", "src/assets"],
|
||||
"assets": [
|
||||
"src/favicon.ico",
|
||||
"src/assets"
|
||||
],
|
||||
"styles": [
|
||||
"./node_modules/@cds/city/css/bundles/default.min.css",
|
||||
"./node_modules/@cds/core/global.min.css",
|
||||
"./node_modules/normalize.css/normalize.css",
|
||||
"node_modules/@clr/icons/clr-icons.min.css",
|
||||
"node_modules/@clr/ui/clr-ui.min.css",
|
||||
"src/styles.scss"
|
||||
],
|
||||
"scripts": []
|
||||
"scripts": [
|
||||
"node_modules/buffer/index.js"
|
||||
]
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"budgets": [
|
||||
{
|
||||
"type": "initial",
|
||||
"maximumWarning": "3mb",
|
||||
"maximumWarning": "500kb",
|
||||
"maximumError": "10mb"
|
||||
},
|
||||
{
|
||||
@@ -74,10 +77,10 @@
|
||||
"builder": "@angular-devkit/build-angular:dev-server",
|
||||
"configurations": {
|
||||
"production": {
|
||||
"browserTarget": "angular-cli:build:production"
|
||||
"browserTarget": "angular-clr:build:production"
|
||||
},
|
||||
"development": {
|
||||
"browserTarget": "angular-cli:build:development"
|
||||
"browserTarget": "angular-clr:build:development"
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "development"
|
||||
@@ -85,7 +88,7 @@
|
||||
"extract-i18n": {
|
||||
"builder": "@angular-devkit/build-angular:extract-i18n",
|
||||
"options": {
|
||||
"browserTarget": "angular-cli:build"
|
||||
"browserTarget": "angular-clr:build"
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
@@ -96,13 +99,17 @@
|
||||
"tsConfig": "tsconfig.spec.json",
|
||||
"karmaConfig": "karma.conf.js",
|
||||
"inlineStyleLanguage": "scss",
|
||||
"assets": ["src/favicon.ico", "src/assets"],
|
||||
"styles": ["src/styles.scss"],
|
||||
"assets": [
|
||||
"src/favicon.ico",
|
||||
"src/assets"
|
||||
],
|
||||
"styles": [
|
||||
"src/styles.scss"
|
||||
],
|
||||
"scripts": []
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultProject": "angular-cli"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
// Karma configuration file, see link for more information
|
||||
// https://karma-runner.github.io/1.0/config/configuration-file.html
|
||||
|
||||
module.exports = function (config) {
|
||||
config.set({
|
||||
basePath: '',
|
||||
frameworks: ['jasmine', '@angular-devkit/build-angular'],
|
||||
plugins: [
|
||||
require('karma-jasmine'),
|
||||
require('karma-chrome-launcher'),
|
||||
require('karma-jasmine-html-reporter'),
|
||||
require('karma-coverage'),
|
||||
require('@angular-devkit/build-angular/plugins/karma')
|
||||
],
|
||||
client: {
|
||||
jasmine: {
|
||||
// you can add configuration options for Jasmine here
|
||||
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
|
||||
// for example, you can disable the random execution with `random: false`
|
||||
// or set a specific seed with `seed: 4321`
|
||||
},
|
||||
clearContext: false // leave Jasmine Spec Runner output visible in browser
|
||||
},
|
||||
jasmineHtmlReporter: {
|
||||
suppressAll: true // removes the duplicated traces
|
||||
},
|
||||
coverageReporter: {
|
||||
dir: require('path').join(__dirname, './coverage/angular-clr'),
|
||||
subdir: '.',
|
||||
reporters: [
|
||||
{ type: 'html' },
|
||||
{ type: 'text-summary' }
|
||||
]
|
||||
},
|
||||
reporters: ['progress', 'kjhtml'],
|
||||
port: 9876,
|
||||
colors: true,
|
||||
logLevel: config.LOG_INFO,
|
||||
autoWatch: true,
|
||||
browsers: ['Chrome'],
|
||||
singleRun: false,
|
||||
restartOnFileChange: true
|
||||
});
|
||||
};
|
||||
Generated
+8635
-7606
File diff suppressed because it is too large
Load Diff
+42
-34
@@ -1,55 +1,63 @@
|
||||
{
|
||||
"name": "angular-cli",
|
||||
"name": "angular-clr",
|
||||
"version": "0.0.0",
|
||||
"scripts": {
|
||||
"ng": "ng",
|
||||
"postinstall": "npm run start",
|
||||
"start": "ng serve",
|
||||
"build": "npm run build-aot && npm run bundle",
|
||||
"watch": "ng build --watch --configuration development",
|
||||
"test": "ng test",
|
||||
"build-aot": "ng build --aot --optimization --build-optimizer",
|
||||
"bundle": "webpack --config webpack-bundle.config.js --progress",
|
||||
"clean": "rm -rf dist/* build/*"
|
||||
"build-aot": "ng build --aot --optimization --build-optimizer",
|
||||
"watch": "ng build --watch --configuration development",
|
||||
"test": "ng test"
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@angular/animations": "~14.0.0",
|
||||
"@angular/common": "~14.0.0",
|
||||
"@angular/compiler": "~14.0.0",
|
||||
"@angular/core": "~14.0.0",
|
||||
"@angular/forms": "~14.0.0",
|
||||
"@angular/platform-browser": "~14.0.0",
|
||||
"@angular/platform-browser-dynamic": "~14.0.0",
|
||||
"@angular/router": "~14.0.0",
|
||||
"@cds/angular": "^6.0.0",
|
||||
"@angular/animations": "^15.2.9",
|
||||
"@angular/cdk": "^15.2.9",
|
||||
"@angular/common": "^15.2.9",
|
||||
"@angular/compiler": "^15.2.9",
|
||||
"@angular/core": "^15.2.9",
|
||||
"@angular/forms": "^15.2.9",
|
||||
"@angular/platform-browser": "^15.2.9",
|
||||
"@angular/platform-browser-dynamic": "^15.2.9",
|
||||
"@angular/router": "^15.2.9",
|
||||
"@cds/angular": "6.6.2",
|
||||
"@cds/city": "^1.1.0",
|
||||
"@cds/core": "^6.0.0",
|
||||
"@clr/angular": "~13.0.0",
|
||||
"@clr/icons": "~13.0.0",
|
||||
"@clr/ui": "~13.0.0",
|
||||
"mini-css-extract-plugin": "^1.6.0",
|
||||
"normalize.css": "^8.0.1",
|
||||
"rxjs": "~6.6.0",
|
||||
"style-loader": "^3.3.1",
|
||||
"tslib": "^2.1.0",
|
||||
"@cds/core": "6.6.2",
|
||||
"@clr/angular": "^15.12.0",
|
||||
"@clr/ui": "^15.12.0",
|
||||
"buffer": "^6.0.3",
|
||||
"modern-normalize": "^1.1.0",
|
||||
"process": "^0.11.10",
|
||||
"rxjs": "~7.5.0",
|
||||
"tslib": "^2.3.0",
|
||||
"zod": "^3.22.4",
|
||||
"zone.js": "~0.11.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular-devkit/build-angular": "~14.0.0",
|
||||
"@angular/cli": "~14.0.0",
|
||||
"@angular/compiler-cli": "~14.0.0",
|
||||
"@types/jasmine": "~3.6.0",
|
||||
"@angular-devkit/build-angular": "^15.2.9",
|
||||
"@angular/cli": "^15.2.9",
|
||||
"@angular/compiler-cli": "^15.2.9",
|
||||
"@types/jasmine": "~3.10.0",
|
||||
"@types/node": "^12.11.1",
|
||||
"css-loader": "^6.7.2",
|
||||
"html-webpack-plugin": "^5.5.0",
|
||||
"browserify-zlib": "^0.2.0",
|
||||
"crypto-browserify": "^3.12.0",
|
||||
"glob": "^10.3.10",
|
||||
"html-webpack-plugin": "^5.5.3",
|
||||
"https-browserify": "^1.0.0",
|
||||
"inline-chunk-html-plugin": "^1.1.1",
|
||||
"jasmine-core": "~3.7.0",
|
||||
"jasmine-core": "~4.0.0",
|
||||
"karma": "~6.3.0",
|
||||
"karma-chrome-launcher": "~3.1.0",
|
||||
"karma-coverage": "~2.0.3",
|
||||
"karma-coverage": "~2.1.0",
|
||||
"karma-jasmine": "~4.0.0",
|
||||
"karma-jasmine-html-reporter": "^1.5.0",
|
||||
"typescript": "~4.7.0"
|
||||
"karma-jasmine-html-reporter": "~1.7.0",
|
||||
"purgecss-webpack-plugin": "^5.0.0",
|
||||
"stream-browserify": "^3.0.0",
|
||||
"stream-http": "^3.2.0",
|
||||
"style-loader": "^3.3.3",
|
||||
"typescript": "~4.9.5",
|
||||
"url": "^0.11.3",
|
||||
"webpack-cli": "^5.1.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,4 +7,4 @@ const routes: Routes = [];
|
||||
imports: [RouterModule.forRoot(routes)],
|
||||
exports: [RouterModule]
|
||||
})
|
||||
export class AppRoutingModule {}
|
||||
export class AppRoutingModule { }
|
||||
|
||||
@@ -7,7 +7,7 @@ import { ShoutboxDataService } from './services/ShoutboxData.service';
|
||||
styleUrls: ['./app.component.scss'],
|
||||
})
|
||||
export class AppComponent implements OnInit{
|
||||
title = 'httXrp';
|
||||
title = 'httXrp Shoutbox';
|
||||
shouts: any[] = []
|
||||
sending = false
|
||||
newShout = {
|
||||
|
||||
@@ -1,116 +1,106 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import { DataParser } from "../util/Dataparser";
|
||||
import { makeTestnetWallet } from "../util/TestnetUtils";
|
||||
import { z } from 'zod';
|
||||
|
||||
declare const xrpIO: any
|
||||
declare const xrpl: any
|
||||
declare const RJSVM: any;
|
||||
declare const RJSVM_Builder: any;
|
||||
declare const Datawriter: any;
|
||||
|
||||
const xrpNode = "wss://s.altnet.rippletest.net:51233"
|
||||
const listeningAddress = "rB4v4taosTUvuup8prxj2wbrBMbmvmxgXx"
|
||||
|
||||
@Injectable()
|
||||
export class ShoutboxDataService {
|
||||
|
||||
public history: any[] = []
|
||||
|
||||
private userWallet1: any
|
||||
private userWallet2: any
|
||||
private shoutboxAddress = "rBGqUNVzrNJ6CNpTriBts8QCTNi5VqUMnZ"
|
||||
private rippleApi: any;
|
||||
private xrpio: any;
|
||||
|
||||
private getTransactions = async () => {
|
||||
const resp = await this.rippleApi.request({
|
||||
command: "account_tx",
|
||||
account: this.shoutboxAddress,
|
||||
forward: false,
|
||||
})
|
||||
return resp.result.transactions.map((entry: any) => entry.tx)
|
||||
}
|
||||
|
||||
private submit = async (shoutHash: string) => {
|
||||
const data = {
|
||||
endpoint: 'submit',
|
||||
data: shoutHash
|
||||
}
|
||||
|
||||
console.log("Submitting shout root hash", data)
|
||||
const submitTx = await this.xrpio.writeRaw({data: JSON.stringify(data)}, this.shoutboxAddress, this.userWallet1.secret)
|
||||
|
||||
console.log("submit TX @", submitTx)
|
||||
|
||||
return submitTx
|
||||
}
|
||||
private dataWriter = undefined as any
|
||||
|
||||
public submitShout = async (shout: any) => {
|
||||
console.log("writing shout data", shout)
|
||||
const shoutHash = await this.xrpio.treeWrite(JSON.stringify(shout), this.userWallet1.address, this.userWallet2.secret)
|
||||
console.log("shout data @ ", shoutHash)
|
||||
return await this.submit(shoutHash)
|
||||
await this.dataWriter.callEndpoint('submit', shout, 10)
|
||||
}
|
||||
|
||||
private parseMemos = async (memos: any) => {
|
||||
const shouts = await Promise.all(memos
|
||||
.map((memo: any) => {
|
||||
if (!memo.Memo || !memo.Memo.MemoData)
|
||||
return
|
||||
|
||||
try {
|
||||
return DataParser.parse('TxHash', hex_to_ascii(memo.Memo.MemoData))
|
||||
} catch (e) {
|
||||
return
|
||||
}
|
||||
})
|
||||
.filter((hash: string) => hash != undefined)
|
||||
.map((root_hash: string) => this.xrpio.treeRead([root_hash]))
|
||||
)
|
||||
return shouts.map((jsonStr: string) => JSON.parse(jsonStr))
|
||||
}
|
||||
|
||||
private loadHistory = async () => {
|
||||
const raw_txs = await this.getTransactions()
|
||||
return await this.parseMemos(raw_txs.flatMap((htx: any) => htx.Memos))
|
||||
}
|
||||
|
||||
private subscribeTxs = async (callback: Function) => {
|
||||
this.rippleApi.on('transaction', (tx: any) => callback(tx))
|
||||
await this.rippleApi.connection.request({
|
||||
command: 'subscribe',
|
||||
accounts: [this.shoutboxAddress]
|
||||
})
|
||||
}
|
||||
|
||||
private listen = async () => {
|
||||
await this.subscribeTxs(async (raw_tx: any) => {
|
||||
const shouts = await this.parseMemos(raw_tx.transaction.Memos)
|
||||
this.history.unshift(...shouts)
|
||||
})
|
||||
}
|
||||
|
||||
initialize = async () => {
|
||||
this.userWallet1 = await makeTestnetWallet()
|
||||
this.userWallet2 = await makeTestnetWallet()
|
||||
|
||||
this.rippleApi = new xrpl.Client(xrpNode)
|
||||
await this.rippleApi.connect()
|
||||
const [userWallet, drainWallet] = await Promise.all([makeTestnetWallet(), makeTestnetWallet()])
|
||||
this.dataWriter = new Datawriter({
|
||||
receiveAddress: drainWallet.address,
|
||||
sendWallet: userWallet,
|
||||
xrpNode: xrpNode,
|
||||
contractAddress: listeningAddress
|
||||
})
|
||||
|
||||
this.xrpio = new xrpIO(xrpNode);
|
||||
await this.xrpio.connect()
|
||||
const shoutSchema = z.object({
|
||||
title: z.string(),
|
||||
body: z.string(),
|
||||
from: z.string(),
|
||||
id: z.optional(z.string())
|
||||
})
|
||||
//type Shout = z.infer<typeof shoutSchema>
|
||||
|
||||
type State = {
|
||||
shouts: any[]
|
||||
}
|
||||
|
||||
// #########################
|
||||
// Define endpoints
|
||||
// #########################
|
||||
|
||||
type RJSVM_Endpoints = {
|
||||
submit: (data: any) => void
|
||||
}
|
||||
|
||||
// #########################
|
||||
// Define init state
|
||||
// #########################
|
||||
|
||||
abstract class RJSVM_Base
|
||||
extends RJSVM<State, RJSVM_Endpoints>
|
||||
{
|
||||
|
||||
owner = userWallet.address
|
||||
|
||||
state: State = {
|
||||
shouts: []
|
||||
}
|
||||
}
|
||||
|
||||
// #########################
|
||||
// Implement logic
|
||||
// #########################
|
||||
|
||||
const RJSVM_Contract = {
|
||||
submit: {
|
||||
implementation: function (env:any, shout:any) {
|
||||
(this as any).state.shouts.unshift(shout)
|
||||
},
|
||||
visibility: 'public',
|
||||
fee: 10,
|
||||
parameterSchema: shoutSchema
|
||||
}
|
||||
}
|
||||
|
||||
// #########################
|
||||
// Build and connect
|
||||
// #########################
|
||||
|
||||
const Rjsvm = RJSVM_Builder.from(RJSVM_Base, RJSVM_Contract);
|
||||
|
||||
const conf = {
|
||||
listeningAddress: listeningAddress,
|
||||
rippleNode: xrpNode
|
||||
}
|
||||
|
||||
const rjsvm = new Rjsvm(conf)
|
||||
await rjsvm.connect()
|
||||
|
||||
this.history = await this.loadHistory()
|
||||
rjsvm.on('error', console.log)
|
||||
rjsvm.on('submit', console.log)
|
||||
|
||||
await this.listen();
|
||||
this.history = rjsvm.state.shouts
|
||||
}
|
||||
}
|
||||
|
||||
export function initShoutboxSvc(svc: ShoutboxDataService): () => Promise<any> {
|
||||
return svc.initialize;
|
||||
}
|
||||
|
||||
function hex_to_ascii(input: any) {
|
||||
var hex = input.toString();
|
||||
var str = '';
|
||||
for (var n = 0; n < hex.length; n += 2) {
|
||||
str += String.fromCharCode(parseInt(hex.substr(n, 2), 16));
|
||||
}
|
||||
return str;
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import { DataParser } from "../util/Dataparser";
|
||||
import { makeTestnetWallet } from "../util/TestnetUtils";
|
||||
|
||||
declare const xrpIO: any
|
||||
declare const xrpl: any
|
||||
|
||||
const xrpNode = "wss://s.altnet.rippletest.net:51233"
|
||||
|
||||
@Injectable()
|
||||
export class ShoutboxDataService {
|
||||
|
||||
public history: any[] = []
|
||||
|
||||
private userWallet1: any
|
||||
private userWallet2: any
|
||||
private shoutboxAddress = "rBGqUNVzrNJ6CNpTriBts8QCTNi5VqUMnZ"
|
||||
private rippleApi: any;
|
||||
private xrpio: any;
|
||||
|
||||
private getTransactions = async () => {
|
||||
const resp = await this.rippleApi.request({
|
||||
command: "account_tx",
|
||||
account: this.shoutboxAddress,
|
||||
forward: false,
|
||||
})
|
||||
return resp.result.transactions.map((entry: any) => entry.tx)
|
||||
}
|
||||
|
||||
private submit = async (shoutHash: string) => {
|
||||
const data = {
|
||||
endpoint: 'submit',
|
||||
data: shoutHash
|
||||
}
|
||||
|
||||
console.log("Submitting shout root hash", data)
|
||||
const submitTx = await this.xrpio.writeRaw({data: JSON.stringify(data)}, this.shoutboxAddress, this.userWallet1.secret)
|
||||
|
||||
console.log("submit TX @", submitTx)
|
||||
|
||||
return submitTx
|
||||
}
|
||||
|
||||
public submitShout = async (shout: any) => {
|
||||
console.log("writing shout data", shout)
|
||||
const shoutHash = await this.xrpio.treeWrite(JSON.stringify(shout), this.userWallet1.address, this.userWallet2.secret)
|
||||
console.log("shout data @ ", shoutHash)
|
||||
return await this.submit(shoutHash)
|
||||
}
|
||||
|
||||
private parseMemos = async (memos: any) => {
|
||||
const shouts = await Promise.all(memos
|
||||
.map((memo: any) => {
|
||||
if (!memo.Memo || !memo.Memo.MemoData)
|
||||
return
|
||||
|
||||
try {
|
||||
return DataParser.parse('TxHash', hex_to_ascii(memo.Memo.MemoData))
|
||||
} catch (e) {
|
||||
return
|
||||
}
|
||||
})
|
||||
.filter((hash: string) => hash != undefined)
|
||||
.map((root_hash: string) => this.xrpio.treeRead([root_hash]))
|
||||
)
|
||||
return shouts.map((jsonStr: string) => JSON.parse(jsonStr))
|
||||
}
|
||||
|
||||
private loadHistory = async () => {
|
||||
const raw_txs = await this.getTransactions()
|
||||
return await this.parseMemos(raw_txs.flatMap((htx: any) => htx.Memos))
|
||||
}
|
||||
|
||||
private subscribeTxs = async (callback: Function) => {
|
||||
this.rippleApi.on('transaction', (tx: any) => callback(tx))
|
||||
await this.rippleApi.connection.request({
|
||||
command: 'subscribe',
|
||||
accounts: [this.shoutboxAddress]
|
||||
})
|
||||
}
|
||||
|
||||
private listen = async () => {
|
||||
await this.subscribeTxs(async (raw_tx: any) => {
|
||||
const shouts = await this.parseMemos(raw_tx.transaction.Memos)
|
||||
this.history.unshift(...shouts)
|
||||
})
|
||||
}
|
||||
|
||||
initialize = async () => {
|
||||
this.userWallet1 = await makeTestnetWallet()
|
||||
this.userWallet2 = await makeTestnetWallet()
|
||||
|
||||
this.rippleApi = new xrpl.Client(xrpNode)
|
||||
await this.rippleApi.connect()
|
||||
|
||||
this.xrpio = new xrpIO(xrpNode);
|
||||
await this.xrpio.connect()
|
||||
|
||||
this.history = await this.loadHistory()
|
||||
|
||||
await this.listen();
|
||||
}
|
||||
}
|
||||
|
||||
export function initShoutboxSvc(svc: ShoutboxDataService): () => Promise<any> {
|
||||
return svc.initialize;
|
||||
}
|
||||
|
||||
function hex_to_ascii(input: any) {
|
||||
var hex = input.toString();
|
||||
var str = '';
|
||||
for (var n = 0; n < hex.length; n += 2) {
|
||||
str += String.fromCharCode(parseInt(hex.substr(n, 2), 16));
|
||||
}
|
||||
return str;
|
||||
}
|
||||
@@ -66,7 +66,7 @@ export class DataParser {
|
||||
|
||||
private static parseTxHash(input: any): TxHash{
|
||||
if(typeof input !== 'string' || !NON_ZERO_TX_HASH.test(input)){
|
||||
throw new Error('Input is not a trasnaction hash')
|
||||
throw new Error(`Input '${input}'is not a trasnaction hash`)
|
||||
}
|
||||
return input
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 948 B |
+16
-19
@@ -1,22 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv='cache-control' content='no-cache'>
|
||||
<meta http-equiv='expires' content='0'>
|
||||
<meta http-equiv='pragma' content='no-cache'>
|
||||
|
||||
<meta charset="utf-8" />
|
||||
<title>httXrp</title>
|
||||
<base href="" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="icon" type="image/x-icon" href="favicon.ico" />
|
||||
<script src="https://cdn.jsdelivr.net/npm/xrpl@2.7.0"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/xrpio@0.1.8/lib/browser/xrpio.browser.js"></script>
|
||||
</head>
|
||||
<head>
|
||||
<script>
|
||||
window.process = { env: { NODE_ENV: 'production' } }
|
||||
</script>
|
||||
|
||||
<body cds-text="body">
|
||||
<app-root>
|
||||
<div style="text-align: center;">Loading application state</div>
|
||||
</app-root>
|
||||
</body>
|
||||
<meta charset="utf-8">
|
||||
<title>AngularClr</title>
|
||||
<base href="/">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/rjsvm@0.2.5/lib/browser/rjsvm.browser.js"></script>
|
||||
</head>
|
||||
<body cds-text="body" cds-theme="dark">
|
||||
<app-root></app-root>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -8,6 +8,5 @@ if (environment.production) {
|
||||
enableProdMode();
|
||||
}
|
||||
|
||||
platformBrowserDynamic()
|
||||
.bootstrapModule(AppModule)
|
||||
platformBrowserDynamic().bootstrapModule(AppModule)
|
||||
.catch(err => console.error(err));
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
* file.
|
||||
*
|
||||
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
|
||||
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
|
||||
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
|
||||
* automatically update themselves. This includes recent versions of Safari, Chrome (including
|
||||
* Opera), Edge on the desktop, and iOS and Chrome on mobile.
|
||||
*
|
||||
* Learn more in https://angular.io/guide/browser-support
|
||||
*/
|
||||
@@ -18,18 +18,6 @@
|
||||
* BROWSER POLYFILLS
|
||||
*/
|
||||
|
||||
/**
|
||||
* IE11 requires the following for NgClass support on SVG elements
|
||||
*/
|
||||
// import 'classlist.js'; // Run `npm install --save classlist.js`.
|
||||
|
||||
/**
|
||||
* Web Animations `@angular/platform-browser/animations`
|
||||
* Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
|
||||
* Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
|
||||
*/
|
||||
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
|
||||
|
||||
/**
|
||||
* By default, zone.js will patch all possible macroTask and DomEvents
|
||||
* user can disable parts of macroTask/DomEvents patch by setting following flags
|
||||
@@ -57,7 +45,13 @@
|
||||
/***************************************************************************************************
|
||||
* Zone JS is required by default for Angular itself.
|
||||
*/
|
||||
import 'zone.js'; // Included with Angular CLI.
|
||||
import 'zone.js'; // Included with Angular CLI.
|
||||
import * as process from 'process';
|
||||
(window as any)['process'] = process;
|
||||
(window as any)['buffer'] = (window as any).Buffer || require('buffer').Buffer;
|
||||
(window as any)['Buffer'] = (window as any).Buffer || require('buffer').Buffer;
|
||||
(window as any)['global'] = (window as any);
|
||||
|
||||
|
||||
/***************************************************************************************************
|
||||
* APPLICATION IMPORTS
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
@import '~modern-normalize/modern-normalize.css';
|
||||
@import '~@cds/core/global.min.css';
|
||||
@import '~@cds/city/css/bundles/default.min.css';
|
||||
@import '~@cds/core/styles/theme.dark.min.css';
|
||||
@import 'modern-normalize/modern-normalize.css';
|
||||
@import '@cds/core/global.min.css';
|
||||
@import '@cds/core/styles/theme.dark.min.css';
|
||||
@import '@cds/city/css/bundles/default.css';
|
||||
|
||||
@import '@clr/ui/shim.cds-core.min.css';
|
||||
@import '@clr/ui/clr-ui.min.css';
|
||||
|
||||
[cds-card-remove-margin] {
|
||||
--color: var(--cds-alias-object-container-border-color);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
||||
|
||||
import 'zone.js/testing';
|
||||
import { getTestBed } from '@angular/core/testing';
|
||||
import {
|
||||
BrowserDynamicTestingModule,
|
||||
platformBrowserDynamicTesting
|
||||
} from '@angular/platform-browser-dynamic/testing';
|
||||
|
||||
// First, initialize the Angular testing environment.
|
||||
getTestBed().initTestEnvironment(
|
||||
BrowserDynamicTestingModule,
|
||||
platformBrowserDynamicTesting(),
|
||||
);
|
||||
@@ -6,6 +6,8 @@
|
||||
"outDir": "./dist/out-tsc",
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"noImplicitOverride": true,
|
||||
"noPropertyAccessFromIndexSignature": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"sourceMap": true,
|
||||
@@ -14,9 +16,23 @@
|
||||
"experimentalDecorators": true,
|
||||
"moduleResolution": "node",
|
||||
"importHelpers": true,
|
||||
"target": "ES2020",
|
||||
"target": "ES2022",
|
||||
"module": "es2020",
|
||||
"lib": ["es2018", "dom"]
|
||||
"lib": [
|
||||
"es2020",
|
||||
"dom"
|
||||
],
|
||||
"useDefineForClassFields": false,
|
||||
"paths": {
|
||||
"stream": ["./node_modules/stream-browserify"],
|
||||
"http": ["./node_modules/stream-http"],
|
||||
"crypto": ["./node_modules/crypto-browserify"],
|
||||
"zlib": ["./node_modules/browserify-zlib"],
|
||||
"https": ["./node_modules/https-browserify"],
|
||||
"url": ["./node_modules/url/"],
|
||||
"buffer": ["./node_modules/buffer/"],
|
||||
"Buffer": ["./node_modules/buffer/"],
|
||||
}
|
||||
},
|
||||
"angularCompilerOptions": {
|
||||
"enableI18nLegacyMessageIdFormat": false,
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./out-tsc/spec",
|
||||
"types": [
|
||||
"jasmine"
|
||||
]
|
||||
},
|
||||
"files": [
|
||||
"src/test.ts",
|
||||
"src/polyfills.ts"
|
||||
],
|
||||
"include": [
|
||||
"src/**/*.spec.ts",
|
||||
"src/**/*.d.ts"
|
||||
]
|
||||
}
|
||||
@@ -4,10 +4,11 @@ const webpack = require('webpack')
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
const distDir = path.resolve(__dirname, 'dist', 'angular-cli')
|
||||
const distDir = path.resolve(__dirname, 'dist', 'angular-clr')
|
||||
const buildDir = path.resolve(__dirname, 'build')
|
||||
const srcDir = path.resolve(__dirname, 'src')
|
||||
|
||||
|
||||
module.exports = {
|
||||
mode: 'production',
|
||||
target: 'web',
|
||||
@@ -21,13 +22,21 @@ module.exports = {
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['', '.js', '.jsx', '.css'],
|
||||
fallback: {
|
||||
}
|
||||
},
|
||||
plugins: [
|
||||
new webpack.ProvidePlugin({
|
||||
Buffer: ['buffer', 'Buffer'],
|
||||
}),
|
||||
new webpack.ProvidePlugin({
|
||||
process: 'process/browser',
|
||||
}),
|
||||
new HtmlWebpackPlugin({
|
||||
inject: "body",
|
||||
template: path.resolve(srcDir, 'index.html'),
|
||||
}),
|
||||
new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/.*/]),
|
||||
new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/.*/])
|
||||
],
|
||||
optimization: {
|
||||
},
|
||||
@@ -39,6 +48,5 @@ module.exports = {
|
||||
},
|
||||
],
|
||||
},
|
||||
externals: {
|
||||
},
|
||||
externals: {},
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
||||
|
||||
if(!process.env['DATA_HASH']){
|
||||
console.log("Environment DATA_HASH not set")
|
||||
|
||||
Reference in New Issue
Block a user