Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Create backend web server implementation with rust framework #37

Open
wants to merge 15 commits into
base: offramp-prototype-staging
Choose a base branch
from

Conversation

b-yap
Copy link

@b-yap b-yap commented Jun 6, 2024

addresses #31

command: RUST_LOG=info cargo run, and it will show:

INFO signer_service_rust: 🚀LISTENING - Ok(127.0.0.1:3001)

Looks like the provided secret key doesn't work on PUBLIC network, so currently I used TESTNET.

@b-yap b-yap changed the base branch from main to offramp-prototype-staging June 6, 2024 14:28
Copy link

github-actions bot commented Jun 6, 2024

yarn.lock changes

Summary

Status Count
ADDED 287
UPDATED 64
DOWNGRADED 1
REMOVED 6
Click to toggle table visibility
Name Status Previous Current
@chainsafe/metamask-polkadot-adapter ADDED - 0.6.0
@chainsafe/metamask-polkadot-types ADDED - 0.7.0
@esbuild-plugins/node-globals-polyfill REMOVED 0.1.1 -
@esbuild-plugins/node-modules-polyfill REMOVED 0.1.4 -
@jspm/core ADDED - 2.0.1
@lit-labs/ssr-dom-shim ADDED - 1.2.0
@lit/reactive-element ADDED - 1.6.3
@motionone/animation ADDED - 10.17.0
@motionone/dom ADDED - 10.17.0
@motionone/easing ADDED - 10.17.0
@motionone/generators ADDED - 10.17.0
@motionone/svelte ADDED - 10.16.4
@motionone/types ADDED - 10.17.0
@motionone/utils ADDED - 10.17.0
@motionone/vue ADDED - 10.16.4
@noble/curves UPDATED 1.0.0 1.4.0
@noble/hashes UPDATED 1.3.0 1.4.0
@parcel/watcher ADDED - 2.4.1
@parcel/watcher-android-arm64 ADDED - 2.4.1
@parcel/watcher-darwin-arm64 ADDED - 2.4.1
@parcel/watcher-darwin-x64 ADDED - 2.4.1
@parcel/watcher-freebsd-x64 ADDED - 2.4.1
@parcel/watcher-linux-arm-glibc ADDED - 2.4.1
@parcel/watcher-linux-arm64-glibc ADDED - 2.4.1
@parcel/watcher-linux-arm64-musl ADDED - 2.4.1
@parcel/watcher-linux-x64-glibc ADDED - 2.4.1
@parcel/watcher-linux-x64-musl ADDED - 2.4.1
@parcel/watcher-wasm ADDED - 2.4.1
@parcel/watcher-win32-arm64 ADDED - 2.4.1
@parcel/watcher-win32-ia32 ADDED - 2.4.1
@parcel/watcher-win32-x64 ADDED - 2.4.1
@polkadot-api/client ADDED - 0.0.1-492c132563ea6b40ae1fc5470dec4cd18768d182.1.0
@polkadot-api/json-rpc-provider ADDED - 0.0.1-492c132563ea6b40ae1fc5470dec4cd18768d182.1.0
@polkadot-api/json-rpc-provider-proxy ADDED - 0.0.1-492c132563ea6b40ae1fc5470dec4cd18768d182.1.0
@polkadot-api/metadata-builders ADDED - 0.0.1-492c132563ea6b40ae1fc5470dec4cd18768d182.1.0
@polkadot-api/substrate-bindings ADDED - 0.0.1-492c132563ea6b40ae1fc5470dec4cd18768d182.1.0
@polkadot-api/substrate-client ADDED - 0.0.1-492c132563ea6b40ae1fc5470dec4cd18768d182.1.0
@polkadot-api/utils ADDED - 0.0.1-492c132563ea6b40ae1fc5470dec4cd18768d182.1.0
@polkadot/api UPDATED 10.6.1 10.13.1
@polkadot/api-augment UPDATED 10.6.1 10.13.1
@polkadot/api-base UPDATED 10.6.1 10.13.1
@polkadot/api-derive UPDATED 10.6.1 10.13.1
@polkadot/extension-dapp ADDED - 0.47.1
@polkadot/extension-inject ADDED - 0.47.1
@polkadot/keyring UPDATED 12.1.2 12.6.2
@polkadot/networks UPDATED 12.1.2 12.6.2
@polkadot/rpc-augment UPDATED 10.6.1 10.13.1
@polkadot/rpc-core UPDATED 10.6.1 10.13.1
@polkadot/rpc-provider UPDATED 10.6.1 10.13.1
@polkadot/types UPDATED 10.6.1 10.13.1
@polkadot/types-augment UPDATED 10.6.1 10.13.1
@polkadot/types-codec UPDATED 10.6.1 10.13.1
@polkadot/types-create UPDATED 10.6.1 10.13.1
@polkadot/types-known UPDATED 10.6.1 10.13.1
@polkadot/types-support UPDATED 10.6.1 10.13.1
@polkadot/util UPDATED 12.1.2 12.6.2
@polkadot/util-crypto UPDATED 12.1.2 12.6.2
@polkadot/wasm-bridge UPDATED 7.1.2 7.3.2
@polkadot/wasm-crypto UPDATED 7.1.2 7.3.2
@polkadot/wasm-crypto-asmjs UPDATED 7.1.2 7.3.2
@polkadot/wasm-crypto-init UPDATED 7.1.2 7.3.2
@polkadot/wasm-crypto-wasm UPDATED 7.1.2 7.3.2
@polkadot/wasm-util UPDATED 7.1.2 7.3.2
@polkadot/x-bigint UPDATED 12.1.2 12.6.2
@polkadot/x-fetch UPDATED 12.1.2 12.6.2
@polkadot/x-global UPDATED 12.1.2 12.6.2
@polkadot/x-randomvalues UPDATED 12.1.2 12.6.2
@polkadot/x-textdecoder UPDATED 12.1.2 12.6.2
@polkadot/x-textencoder UPDATED 12.1.2 12.6.2
@polkadot/x-ws UPDATED 12.1.2 12.6.2
@scure/base UPDATED 1.1.1 1.1.6
@stablelib/aead ADDED - 1.0.1
@stablelib/binary ADDED - 1.0.1
@stablelib/bytes ADDED - 1.0.1
@stablelib/chacha ADDED - 1.0.1
@stablelib/chacha20poly1305 ADDED - 1.0.1
@stablelib/constant-time ADDED - 1.0.1
@stablelib/ed25519 ADDED - 1.0.3
@stablelib/hash ADDED - 1.0.1
@stablelib/hkdf ADDED - 1.0.1
@stablelib/hmac ADDED - 1.0.1
@stablelib/int ADDED - 1.0.1
@stablelib/keyagreement ADDED - 1.0.1
@stablelib/poly1305 ADDED - 1.0.1
@stablelib/random ADDED - 1.0.2
@stablelib/sha256 ADDED - 1.0.1
@stablelib/sha512 ADDED - 1.0.1
@stablelib/wipe ADDED - 1.0.1
@stablelib/x25519 ADDED - 1.0.3
@stellar/js-xdr ADDED - 3.1.1
@stellar/stellar-base ADDED - 11.0.1
@substrate/connect UPDATED 0.7.26 0.8.8
@substrate/connect-extension-protocol UPDATED 1.0.1 2.0.0
@substrate/connect-known-chains ADDED - 1.1.4
@substrate/light-client-extension-helpers ADDED - 0.0.4
@substrate/ss58-registry UPDATED 1.40.0 1.47.0
@talismn/connect-components ADDED - 1.1.8
@talismn/connect-ui ADDED - 1.1.3
@talismn/connect-wallets ADDED - 1.2.5
@tanstack/query-core ADDED - 5.31.0
@tanstack/react-query ADDED - 5.31.0
@testing-library/react ADDED - 13.4.0
@trysound/sax ADDED - 0.2.0
@types/bn.js UPDATED 5.1.1 5.1.5
@types/cssnano ADDED - 5.0.0
@types/react UPDATED 18.2.5 18.2.79
@types/react-dom ADDED - 18.2.25
@types/trusted-types ADDED - 2.0.7
@walletconnect/core ADDED - 2.12.2
@walletconnect/environment ADDED - 1.0.1
@walletconnect/events ADDED - 1.0.1
@walletconnect/heartbeat ADDED - 1.2.1
@walletconnect/jsonrpc-http-connection ADDED - 1.0.7
@walletconnect/jsonrpc-provider ADDED - 1.0.13
@walletconnect/jsonrpc-types ADDED - 1.0.3
@walletconnect/jsonrpc-utils ADDED - 1.0.8
@walletconnect/jsonrpc-ws-connection ADDED - 1.0.14
@walletconnect/keyvaluestorage ADDED - 1.1.1
@walletconnect/logger ADDED - 2.1.2
@walletconnect/modal ADDED - 2.6.2
@walletconnect/modal-core ADDED - 2.6.2
@walletconnect/modal-ui ADDED - 2.6.2
@walletconnect/relay-api ADDED - 1.0.10
@walletconnect/relay-auth ADDED - 1.0.4
@walletconnect/safe-json ADDED - 1.0.2
@walletconnect/sign-client ADDED - 2.12.2
@walletconnect/time ADDED - 1.0.2
@walletconnect/types ADDED - 2.12.2
@walletconnect/universal-provider ADDED - 2.12.2
@walletconnect/utils ADDED - 2.12.2
@walletconnect/window-getters ADDED - 1.0.1
@walletconnect/window-metadata ADDED - 1.0.1
acorn UPDATED 8.8.2 8.11.3
ansi-escapes UPDATED 6.2.0 6.2.1
atomic-sleep ADDED - 1.0.0
axios ADDED - 1.6.8
base32.js ADDED - 0.1.0
base64-js ADDED - 1.5.1
bignumber.js ADDED - 9.1.2
binary-extensions ADDED - 2.3.0
boolbase ADDED - 1.0.0
buffer ADDED - 6.0.3
caniuse-api ADDED - 3.0.0
caniuse-lite UPDATED 1.0.30001482 1.0.30001612
chokidar ADDED - 3.6.0
citty ADDED - 0.1.6
clipboardy ADDED - 4.0.0
colord ADDED - 2.9.3
concat-with-sourcemaps ADDED - 1.1.0
confbox ADDED - 0.1.7
consola ADDED - 3.2.3
cookie-es ADDED - 1.1.0
cross-fetch ADDED - 3.1.8
crossws ADDED - 0.2.4
css-declaration-sorter ADDED - 6.4.1
css-select ADDED - 4.3.0
css-tree ADDED - 1.1.3
css-what ADDED - 6.1.0
cssesc ADDED - 3.0.0
cssnano ADDED - 5.1.15
cssnano-preset-default ADDED - 5.2.14
cssnano-utils ADDED - 3.1.0
csso ADDED - 4.2.0
decamelize ADDED - 1.2.0
decode-uri-component ADDED - 0.2.2
defu ADDED - 6.1.4
destr ADDED - 2.0.3
detect-browser ADDED - 5.3.0
detect-libc ADDED - 1.0.3
dijkstrajs ADDED - 1.0.3
dom-serializer ADDED - 1.4.1
domelementtype ADDED - 2.3.0
domhandler ADDED - 4.3.1
domutils ADDED - 2.8.0
duplexify ADDED - 4.1.3
electron-to-chromium UPDATED 1.4.382 1.4.745
encode-utf8 ADDED - 1.0.3
end-of-stream ADDED - 1.4.4
esbuild-plugin-polyfill-node ADDED - 0.3.0
events ADDED - 3.3.0
eventsource ADDED - 2.0.2
fast-redact ADDED - 3.5.0
filter-obj ADDED - 1.1.0
follow-redirects ADDED - 1.15.6
fs-extra ADDED - 10.1.0
function-bind UPDATED 1.1.1 1.1.2
generic-names ADDED - 4.0.0
get-port-please ADDED - 3.1.2
h3 ADDED - 1.11.1
hasown ADDED - 2.0.2
hey-listen ADDED - 1.0.8
http-shutdown ADDED - 1.2.2
husky UPDATED 8.0.3 9.0.11
icss-replace-symbols ADDED - 1.1.0
icss-utils ADDED - 5.1.0
idb-keyval ADDED - 6.2.1
ieee754 ADDED - 1.2.1
import-cwd ADDED - 3.0.0
import-from ADDED - 3.0.0
import-meta-resolve ADDED - 3.1.1
iron-webcrypto ADDED - 1.1.1
is-binary-path ADDED - 2.1.0
is-core-module UPDATED 2.12.0 2.13.1
is-docker ADDED - 3.0.0
is-inside-container ADDED - 1.0.0
is-wsl ADDED - 3.1.0
is64bit ADDED - 2.0.0
isomorphic-unfetch ADDED - 3.1.0
jiti ADDED - 1.21.0
jsonfile ADDED - 6.1.0
keyvaluestorage-interface ADDED - 1.0.0
lint-staged UPDATED 15.2.0 15.2.2
listhen ADDED - 1.7.2
listr2 UPDATED 8.0.0 8.0.1
lit ADDED - 2.8.0
lit-element ADDED - 3.3.3
lit-html ADDED - 2.8.0
loader-utils ADDED - 3.2.1
lodash.camelcase ADDED - 4.3.0
lodash.isequal ADDED - 4.5.0
lodash.memoize ADDED - 4.1.2
lodash.uniq ADDED - 4.5.0
lru-cache UPDATED 10.0.1 10.2.0
magic-string REMOVED 0.25.9 -
mdn-data ADDED - 2.0.14
mime ADDED - 3.0.0
mlly ADDED - 1.6.1
mock-socket UPDATED 9.2.1 9.3.1
motion ADDED - 10.16.2
mri ADDED - 1.2.0
multiformats ADDED - 9.9.0
nanoid UPDATED 3.3.6 3.3.7
napi-wasm ADDED - 1.1.0
nock UPDATED 13.3.1 13.5.4
node-addon-api ADDED - 7.1.0
node-fetch UPDATED 3.3.1 3.3.2
node-fetch-native ADDED - 1.6.4
node-forge ADDED - 1.3.1
node-gyp-build UPDATED 4.6.0 4.8.0
node-releases UPDATED 2.0.10 2.0.14
normalize-url ADDED - 6.1.0
npm-run-path UPDATED 5.1.0 5.3.0
nth-check ADDED - 2.1.1
ofetch ADDED - 1.3.4
ohash ADDED - 1.1.3
on-exit-leak-free ADDED - 0.2.0
p-finally ADDED - 1.0.0
p-queue ADDED - 6.6.2
p-timeout ADDED - 3.2.0
pathe ADDED - 1.1.2
pify ADDED - 5.0.0
pino ADDED - 7.11.0
pino-abstract-transport ADDED - 0.5.0
pino-std-serializers ADDED - 4.0.0
pkg-types ADDED - 1.1.0
pngjs ADDED - 5.0.0
postcss UPDATED 8.4.23 8.4.38
postcss-calc ADDED - 8.2.4
postcss-colormin ADDED - 5.3.1
postcss-convert-values ADDED - 5.1.3
postcss-discard-comments ADDED - 5.1.2
postcss-discard-duplicates ADDED - 5.1.0
postcss-discard-empty ADDED - 5.1.1
postcss-discard-overridden ADDED - 5.1.0
postcss-load-config ADDED - 3.1.4
postcss-merge-longhand ADDED - 5.1.7
postcss-merge-rules ADDED - 5.1.4
postcss-minify-font-values ADDED - 5.1.0
postcss-minify-gradients ADDED - 5.1.1
postcss-minify-params ADDED - 5.1.4
postcss-minify-selectors ADDED - 5.2.1
postcss-modules ADDED - 6.0.0
postcss-modules-extract-imports ADDED - 3.1.0
postcss-modules-local-by-default ADDED - 4.0.5
postcss-modules-scope ADDED - 3.2.0
postcss-modules-values ADDED - 4.0.0
postcss-normalize-charset ADDED - 5.1.0
postcss-normalize-display-values ADDED - 5.1.0
postcss-normalize-positions ADDED - 5.1.1
postcss-normalize-repeat-style ADDED - 5.1.1
postcss-normalize-string ADDED - 5.1.0
postcss-normalize-timing-functions ADDED - 5.1.0
postcss-normalize-unicode ADDED - 5.1.1
postcss-normalize-url ADDED - 5.1.0
postcss-normalize-whitespace ADDED - 5.1.1
postcss-ordered-values ADDED - 5.1.3
postcss-reduce-initial ADDED - 5.1.2
postcss-reduce-transforms ADDED - 5.1.0
postcss-selector-parser ADDED - 6.0.16
postcss-svgo ADDED - 5.1.0
postcss-unique-selectors ADDED - 5.1.1
postcss-value-parser ADDED - 4.2.0
process-warning ADDED - 1.0.0
promise.series ADDED - 0.2.0
proxy-compare ADDED - 2.5.1
proxy-from-env ADDED - 1.1.0
qrcode ADDED - 1.5.3
query-string ADDED - 7.1.3
quick-format-unescaped ADDED - 4.0.4
radix3 ADDED - 1.1.2
randombytes ADDED - 2.1.0
react ADDED - 18.2.0
react-daisyui ADDED - 5.0.0
react-dom ADDED - 18.2.0
react-native-compat ADDED - 1.0.0
readdirp ADDED - 3.6.0
real-require ADDED - 0.1.0
require-main-filename ADDED - 2.0.0
reserved-words ADDED - 0.1.2
rfdc UPDATED 1.3.0 1.3.1
rollup-plugin-inject REMOVED 3.0.2 -
rollup-plugin-node-polyfills REMOVED 0.2.1 -
rollup-plugin-postcss ADDED - 4.0.2
rollup-plugin-postcss-modules ADDED - 2.1.1
rollup-plugin-styles ADDED - 4.0.0
safe-identifier ADDED - 0.4.2
safe-stable-stringify ADDED - 2.4.3
scale-ts ADDED - 1.6.0
scheduler ADDED - 0.23.0
sha.js ADDED - 2.4.11
smoldot UPDATED 1.0.4 2.0.22
sodium-native ADDED - 4.1.1
sonic-boom ADDED - 2.8.0
source-map-js UPDATED 1.0.2 1.2.0
sourcemap-codec REMOVED 1.4.8 -
split-on-first ADDED - 1.1.0
split2 ADDED - 4.2.0
stable ADDED - 0.1.8
std-env ADDED - 3.7.0
stellar-base ADDED - 11.0.1
stellar-sdk ADDED - 11.3.0
stream-shift ADDED - 1.0.3
strict-uri-encode ADDED - 2.0.0
string-hash ADDED - 1.1.3
string-width UPDATED 7.0.0 7.1.0
style-inject ADDED - 0.3.0
stylehacks ADDED - 5.1.1
svgo ADDED - 2.8.0
system-architecture ADDED - 0.1.0
thread-stream ADDED - 0.15.2
toml ADDED - 3.0.0
tslib UPDATED 2.5.0 2.6.2
type-fest DOWNGRADED 3.13.1 0.21.3
ufo ADDED - 1.5.3
uint8arrays ADDED - 3.1.1
uncrypto ADDED - 0.1.3
unenv ADDED - 1.9.0
unfetch ADDED - 4.2.0
universalify UPDATED 0.2.0 2.0.1
unstorage ADDED - 1.10.2
untun ADDED - 0.1.3
update-browserslist-db UPDATED 1.0.11 1.0.13
uqr ADDED - 0.1.2
urijs ADDED - 1.19.11
use-sync-external-store ADDED - 1.2.0
valtio ADDED - 1.11.2
which-module ADDED - 2.0.1
ws UPDATED 8.13.0 8.16.0

Copy link

netlify bot commented Jun 7, 2024

‼️ Deploy request for pendulum-pay rejected.

Name Link
🔨 Latest commit 8fd04eb

@b-yap b-yap requested review from TorstenStueber and ebma and removed request for TorstenStueber and ebma June 11, 2024 10:20
@b-yap
Copy link
Author

b-yap commented Jun 11, 2024

@ebma @bogdanS98 @gianfra-t Initial review

Copy link
Contributor

@gianfra-t gianfra-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! I really like more the rust version of the back-end. It's very neat @b-yap 👍.

I just left a few comments but not critical. The only thing is that I couldn't run this on my pc, I get Library not loaded: @rpath/libpq.5.dylib. Do I need to install postgres maybe?

let mut tx = create_transaction_no_operations(
funding_account.public_key(),
// increment the sequence number
sequence + 1,
Copy link
Contributor

@gianfra-t gianfra-t Jun 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we increase the sequence by one here? In the js backend we didn't need to.

Is it because new TransactionBuilder on the js library will increase by 1 internally while substrate-stellar-sdk doesn't?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this answer my question 😅. You can ignore this one.


match memo_type.as_str() {
"1" | "text" | "memotext" => {
let memo = self.memo.clone().into_bytes();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to use the Memo implementation to build from string here to simplify this conversion a bit? WDYT?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

let _memo = self.memo.as_bytes();
let mut memo = [0;32];
memo[.._memo.len()].copy_from_slice(_memo);
Ok(Memo::MemoHash(memo))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thought as the above with from_hash_memo, although I'm not sure if IntoHash is implemented for [u8] here.

Copy link
Author

@b-yap b-yap Jun 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, IntoHash is not implemented for &[u8] and Vec<u8>.
It can accept Hash or [u8;32], which is already the type of the Enum tuple:

pub enum Memo {
     ...
    MemoHash(Hash),
    ....
}

But your comment helped discover a problem with the previous code. Decoding from base64 is actually required (which I didn't do):

 transactionMemo = Memo.hash(Buffer.from(memo, "base64"));

return failed_status;
};

if native_balance.balance < 2.5 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can use a multiple of NEW_ACCOUNT_STARTING_BALANCE defined here since this account will always need at least a bit more than that.

Copy link
Member

@ebma ebma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really cool implementation 👍 We of course don't need the database yet (and probably wouldn't use it to store the token info) but it's nice to already see how easy it is to deal with the schemas with diesel.

I would suggest we keep the code around and switch from the Typescript/express backend to this one either once we identify the need to use databases in the prototype, or when we reach a state where we want move away from the prototype and aim for a more production-ready/stable backend.

signer-service-rust/src/main.rs Outdated Show resolved Hide resolved
signer-service-rust/src/config/account.rs Outdated Show resolved Hide resolved
signer-service-rust/src/config/database.rs Outdated Show resolved Hide resolved
signer-service-rust/src/config/server.rs Outdated Show resolved Hide resolved
and update memohash
@b-yap b-yap force-pushed the 31-create-backend-web-server-implementation-with-rust-framework branch from 01d9d7b to 8fd04eb Compare June 17, 2024 15:46
@b-yap
Copy link
Author

b-yap commented Jun 17, 2024

I just left a few comments but not critical. The only thing is that I couldn't run this on my pc, I get Library not loaded: @rpath/libpq.5.dylib. Do I need to install postgres maybe?

@gianfra-t Yes you will need postgres for this. I have updated the README to either install it in your machine, or use docker.

@ebma
Copy link
Member

ebma commented Jun 17, 2024

I also added a note on how to install it via brew to the README.

Copy link
Contributor

@bogdanS98 bogdanS98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great implementation @b-yap 🚀! I only have one question.

Is the infra folder supposed to contain anything else than the models, schemas and db interaction code in the future? If not, then I think we could rename it to something like db so that it's a bit clearer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants