fix browser issues for good hopefully
This commit is contained in:
Generated
+888
-4276
File diff suppressed because it is too large
Load Diff
+7
-4
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "rjsvm",
|
||||
"version": "0.3.2",
|
||||
"version": "0.4.1",
|
||||
"description": "",
|
||||
"main": "lib/src/main.js",
|
||||
"scripts": {
|
||||
@@ -16,13 +16,16 @@
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"axios": "^1.7.7",
|
||||
"stream-http": "^3.2.0",
|
||||
"url": "^0.11.3",
|
||||
"xrpio": "^0.3.0",
|
||||
"rjsvm": "^0.4.0",
|
||||
"xrpio": "^0.4.0",
|
||||
"xrpl": "^4.0.0",
|
||||
"zod": "^3.21.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"node-polyfill-webpack-plugin": "^4.0.0",
|
||||
"stream-http": "^3.2.0",
|
||||
"url": "^0.11.3",
|
||||
|
||||
"@types/chai": "^4.3.6",
|
||||
"@types/expect": "^1.20.4",
|
||||
"@types/mocha": "^5.2.7",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { PaymentTx_T, ParameterizedFunction, Payload, RJSVM, RJSVM_Config, RJSVM_Implementations, Function_Map, Endpoints_Of, State_Of, Generic_Ctor_ReturnType, RJSVM_Endpoint } from "./types"
|
||||
import { AccountTxTransaction, Client as Xrpl } from 'xrpl';
|
||||
import { Client as Xrpl } from 'xrpl';
|
||||
import { xrpIO } from 'xrpio';
|
||||
import { DataParser } from "../../util/dataparser";
|
||||
import { XRP_ADDRESS } from "../../util/protocol.constants";
|
||||
@@ -47,7 +47,7 @@ export abstract class RJSVM_Builder {
|
||||
this.rippleApi = new Xrpl(this.config.rippleNode)
|
||||
await this.rippleApi.connect()
|
||||
|
||||
this.xrpIO = new xrpIO(this.config.rippleNode);
|
||||
this.xrpIO = new xrpIO(this.config.rippleNode, { readFreshApi: false });
|
||||
await this.xrpIO.connect()
|
||||
await this.sync()
|
||||
|
||||
@@ -191,26 +191,19 @@ export abstract class RJSVM_Builder {
|
||||
marker: marker,
|
||||
})
|
||||
|
||||
//results may not be ordered, so sort them
|
||||
const raw_txs = await Promise.all(
|
||||
resp.result.transactions
|
||||
.filter(tx => tx.tx_json.TransactionType === "Payment")
|
||||
.sort((a,b) => a.tx_json.ledger_index - b.tx_json.ledger_index)
|
||||
.map((tx) => this.xrpIO.getTransaction(tx.hash))
|
||||
)
|
||||
|
||||
//XRPL API update adaption
|
||||
await Promise.all(
|
||||
raw_txs
|
||||
.filter(tx => !!tx.result.tx_json.Memos)
|
||||
const full_txs = resp.result.transactions
|
||||
.filter(tx => !!tx.tx_json.Memos)
|
||||
.map(tx => {
|
||||
return ({
|
||||
...tx.result.tx_json,
|
||||
hash: tx.result.hash,
|
||||
Amount: tx.result.tx_json["DeliverMax"],
|
||||
inLedger: tx.result.tx_json['ledger_index']
|
||||
...tx.tx_json,
|
||||
hash: tx.hash,
|
||||
Amount: tx.tx_json["DeliverMax"],
|
||||
inLedger: tx.tx_json['ledger_index']
|
||||
} as PaymentTx_T)
|
||||
})
|
||||
|
||||
await Promise.all(
|
||||
full_txs
|
||||
.map(tx => this.parseMemos(tx))
|
||||
)
|
||||
|
||||
@@ -222,7 +215,7 @@ export abstract class RJSVM_Builder {
|
||||
//presence of no marker means we caught up to current block height
|
||||
this.sync_block_height = resp.result.ledger_index_max + 1
|
||||
//schedule the next sync
|
||||
this.syncTimeout = setTimeout(this.sync, 10000)
|
||||
this.syncTimeout = setTimeout(this.sync, 5000)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,3 +2,4 @@ export * from "./RJSVM/framework/rjsvm"
|
||||
export * from "./RJSVM/datawriter/datawriter"
|
||||
export * from "./RJSVM/framework/types"
|
||||
export * from "./util/dataparser"
|
||||
export * from "zod"
|
||||
@@ -142,6 +142,7 @@ const setup = async () => {
|
||||
await rjsvm.connect()
|
||||
}
|
||||
|
||||
|
||||
describe('RJSVM basic functions', () => {
|
||||
|
||||
before(async function () {
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<script src="../lib/browser/rjsvm.browser.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div style="text-align: center;"></div>
|
||||
<script>
|
||||
|
||||
const xrpNode = "wss://s.altnet.rippletest.net:51233"
|
||||
const listeningAddress = "rMBYWyxGx1b5zEjJKF18TTwF5X3vP2WyjR"
|
||||
|
||||
const drainWallet = {
|
||||
address: "rLNEG2ubbW3HUHYL7QCunNX96QrZzq2Udo",
|
||||
secret: "sEd7FusyxBpT1JLQjS76nnn4JABredu"
|
||||
}
|
||||
|
||||
const sendWallet = {
|
||||
address: "rnNuTh8catLz5T12e1fwbxH3FWvUZCYYTw",
|
||||
secret: "sEdSqxN99gFoZ2s8ru7RNCvEXFBmVYa"
|
||||
}
|
||||
|
||||
this.dataWriter = new Datawriter({
|
||||
receiveAddress: drainWallet.address,
|
||||
sendWallet: sendWallet,
|
||||
xrpNode: xrpNode,
|
||||
contractAddress: listeningAddress
|
||||
})
|
||||
|
||||
const shoutSchema = z.object({
|
||||
title: z.string(),
|
||||
body: z.string(),
|
||||
from: z.string(),
|
||||
hash: z.optional(z.string()),
|
||||
date: z.optional(z.string()),
|
||||
id: z.optional(z.string())
|
||||
})
|
||||
|
||||
|
||||
// #########################
|
||||
// Define endpoints
|
||||
// #########################
|
||||
|
||||
|
||||
// #########################
|
||||
// Define init state
|
||||
// #########################
|
||||
|
||||
class RJSVM_Base
|
||||
extends RJSVM {
|
||||
|
||||
owner = sendWallet.address
|
||||
|
||||
state = {}
|
||||
}
|
||||
|
||||
// #########################
|
||||
// Implement logic
|
||||
// #########################
|
||||
|
||||
const RJSVM_Contract = {
|
||||
submit: {
|
||||
implementation: function (env, shout) {
|
||||
shout.hash = env.hash;
|
||||
const d = new Date("2000-01-01");
|
||||
d.setSeconds(d.getSeconds() + env.date)
|
||||
shout.date = d.toLocaleString("de-DE")
|
||||
},
|
||||
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)
|
||||
rjsvm.connect()
|
||||
|
||||
rjsvm.on('error', console.log)
|
||||
rjsvm.on('submit', console.log)
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
+4
-8
@@ -1,6 +1,8 @@
|
||||
const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
const BomPlugin = require('webpack-utf8-bom');
|
||||
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
|
||||
|
||||
|
||||
module.exports = {
|
||||
mode: 'production',
|
||||
@@ -14,14 +16,7 @@ module.exports = {
|
||||
resolve: {
|
||||
extensions: [".ts", ".tsx", ".js"],
|
||||
fallback: {
|
||||
"zlib": require.resolve("browserify-zlib"),
|
||||
"http": require.resolve("stream-http"),
|
||||
"https": require.resolve("https-browserify"),
|
||||
"stream": require.resolve("stream-browserify") ,
|
||||
"buffer": require.resolve('buffer/'),
|
||||
"Buffer": require.resolve('buffer/'),
|
||||
"url": require.resolve('url/'),
|
||||
"crypto": require.resolve('crypto-browserify'),
|
||||
buffer: require.resolve('buffer/'),
|
||||
}
|
||||
},
|
||||
module: {
|
||||
@@ -33,6 +28,7 @@ module.exports = {
|
||||
minimize: true,
|
||||
},
|
||||
plugins: [
|
||||
new NodePolyfillPlugin(),
|
||||
new webpack.ProvidePlugin({
|
||||
Buffer: ['buffer', 'Buffer'],
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user