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

Update stellar-sdk + remove soroban-client #730

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@
"regenerator-runtime": "^0.13.9",
"route-recognizer": "^0.3.4",
"solar-stellarorg": "git+https://github.com/stellar/solar-stellarorg#master",
"soroban-client": "^1.0.0-beta.2",
"stellar-sdk": "^11.0.0-beta.4",
"stellar-sdk": "^11.0.0-beta.6",
"typescript": "^4.5.5",
"uri-templates": "^0.2.0",
"urijs": "^1.16.0"
Expand Down
2 changes: 1 addition & 1 deletion src/actions/endpointExplorer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from "axios";
import { CallBuilder } from "stellar-sdk/lib/call_builder";
import { CallBuilder } from "stellar-sdk";
import URI from "urijs";
import dispatchInNewStack from "../helpers/dispatchInNewStack";

Expand Down
20 changes: 12 additions & 8 deletions src/actions/xdrViewer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as StellarSdk from "stellar-sdk";
import * as SorobanSdk from "soroban-client";
import axios from "axios";
import { FETCH_SEQUENCE_FAIL } from "actions/transactionBuilder";
import { SIGNATURE } from "../constants/signature";
Expand Down Expand Up @@ -44,12 +43,13 @@ export function fetchSigners(
networkPassphrase,
isSoroban = false,
) {
const sdk = isSoroban ? SorobanSdk : StellarSdk;

return (dispatch) => {
dispatch({ type: FETCHED_SIGNERS.PENDING });
try {
let tx = new sdk.TransactionBuilder.fromXDR(input, networkPassphrase);
let tx = new StellarSdk.TransactionBuilder.fromXDR(
input,
networkPassphrase,
);

// Extract all source accounts from transaction (base transaction, and all operations)
let sourceAccounts = {};
Expand All @@ -58,7 +58,7 @@ export function fetchSigners(
// inner signatures in a fee bump transaction
let groupedSignatures = [];

if (tx instanceof sdk.FeeBumpTransaction) {
if (tx instanceof StellarSdk.FeeBumpTransaction) {
sourceAccounts[
convertMuxedAccountToEd25519Account(tx.feeSource)
] = true;
Expand Down Expand Up @@ -117,12 +117,16 @@ export function fetchSigners(
// tx hash in signatures array, so we can ignore pre-authorized transactions here.
switch (signer.type) {
case "sha256_hash":
const hashXSigner = sdk.StrKey.decodeSha256Hash(signer.key);
const hashXSignature = sdk.hash(sigObj.sig);
const hashXSigner = StellarSdk.StrKey.decodeSha256Hash(
signer.key,
);
const hashXSignature = StellarSdk.hash(sigObj.sig);
isValid = hashXSigner.equals(hashXSignature);
break;
case "ed25519_public_key":
const keypair = sdk.Keypair.fromPublicKey(signer.key);
const keypair = StellarSdk.Keypair.fromPublicKey(
signer.key,
);
isValid = keypair.verify(txHash, sigObj.sig);
break;
}
Expand Down
12 changes: 8 additions & 4 deletions src/components/TxSubmitterResult.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useReducer } from "react";
import {
Server,
TransactionBuilder,
AccountRequiresMemoError,
BadResponseError,
Expand Down Expand Up @@ -29,7 +28,10 @@ const initialState = {

const reducer = (
state: any,
action: { type: ACTIONS; payload?: Horizon.SubmitTransactionResponse },
action: {
type: ACTIONS;
payload?: Horizon.HorizonApi.SubmitTransactionResponse;
},
) => {
switch (action.type) {
case ACTIONS.submit:
Expand Down Expand Up @@ -83,7 +85,9 @@ export const TxSubmitterResult = ({
txXdr,
networkPassphrase,
);
const server = new Server(horizonURL, { appName: "Laboratory" });
const server = new Horizon.Server(horizonURL, {
appName: "Laboratory",
});
server.submitTransaction(transaction).then(
(res) => {
dispatch({ type: ACTIONS.success, payload: res });
Expand Down Expand Up @@ -123,7 +127,7 @@ const Response = ({
result_xdr,
result_meta_xdr,
fee_meta_xdr,
}: ResponseProps & Horizon.TransactionResponse) => (
}: ResponseProps & Horizon.HorizonApi.TransactionResponse) => (
<div className="XdrViewer__submit so-back TransactionSubmitter__result">
<div className="so-chunk">
<h3
Expand Down
3 changes: 1 addition & 2 deletions src/constants/network.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Networks } from "stellar-sdk";
import { Networks as SorobanNetworks } from "soroban-client";

const NETWORK = {
available: {
futurenet: {
horizonURL: "https://horizon-futurenet.stellar.org",
networkPassphrase: SorobanNetworks.FUTURENET,
networkPassphrase: Networks.FUTURENET,
},
test: {
horizonURL: "https://horizon-testnet.stellar.org",
Expand Down
8 changes: 3 additions & 5 deletions src/helpers/Libify.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// the best choice since source code differs based on content.

import * as Sdk from "stellar-sdk";
import * as SorobanSdk from "soroban-client";
import defaults from "lodash/defaults";
import each from "lodash/each";
import has from "lodash/has";
Expand Down Expand Up @@ -881,15 +880,14 @@ Libify.signTransaction = function (
ledgerWalletSigs,
isSoroban = false,
) {
const sdk = isSoroban ? SorobanSdk : Sdk;
let validSecretKeys = [];
let validPreimages = [];
for (let i = 0; i < signers.length; i++) {
let signer = signers[i];
if (signer !== null && !isUndefined(signer) && signer !== "") {
// Signer
if (signer.charAt(0) == "S") {
if (!sdk.StrKey.isValidEd25519SecretSeed(signer)) {
if (!Sdk.StrKey.isValidEd25519SecretSeed(signer)) {
return {
message: "One of secret keys is invalid",
};
Expand All @@ -907,13 +905,13 @@ Libify.signTransaction = function (
}
}

let newTx = sdk.TransactionBuilder.fromXDR(txXdr, networkPassphrase);
let newTx = Sdk.TransactionBuilder.fromXDR(txXdr, networkPassphrase);
let existingSigs = newTx.signatures.length;
let addedSigs = 0;

each(validSecretKeys, (signer) => {
addedSigs++;
newTx.sign(sdk.Keypair.fromSecret(signer));
newTx.sign(Sdk.Keypair.fromSecret(signer));
});
each(validPreimages, (signer) => {
addedSigs++;
Expand Down
16 changes: 4 additions & 12 deletions src/helpers/extrapolateFromXdr.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
// - object: typed values always with a type and value `{type: 'code', value: 'Foo();'}`

import * as StellarSdk from "stellar-sdk";
import * as SorobanSdk from "soroban-client";
import isArray from "lodash/isArray";
import isString from "lodash/isString";
import functionsIn from "lodash/functionsIn";
Expand All @@ -22,17 +21,10 @@ export default function extrapolateFromXdr(input, type, isSoroban = false) {
// TODO: input validation

let xdr, StrKey, Keypair, Operation;
if (isSoroban) {
xdr = SorobanSdk.xdr;
StrKey = SorobanSdk.StrKey;
Keypair = SorobanSdk.Keypair;
Operation = SorobanSdk.Operation;
} else {
xdr = StellarSdk.xdr;
StrKey = StellarSdk.StrKey;
Keypair = StellarSdk.Keypair;
Operation = StellarSdk.Operation;
}
xdr = StellarSdk.xdr;
StrKey = StellarSdk.StrKey;
Keypair = StellarSdk.Keypair;
Operation = StellarSdk.Operation;

function buildTreeFromObject(object, anchor, name) {
anchor.type = name;
Expand Down
6 changes: 1 addition & 5 deletions src/helpers/validateTxXdr.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import trim from "lodash/trim";
import * as StellarSdk from "stellar-sdk";
import * as SorobanSdk from "soroban-client";
import { validateBase64 } from "./validateBase64";

export const validateTxXdr = (input: string, isSoroban = false) => {
export const validateTxXdr = (input: string) => {
let xdr = StellarSdk.xdr;
if (isSoroban) {
xdr = SorobanSdk.xdr;
}
input = trim(input);

let base64Validation = validateBase64(input);
Expand Down
19 changes: 6 additions & 13 deletions src/views/TransactionSigner.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useDispatch } from "react-redux";
import * as StellarSdk from "stellar-sdk";
import * as SorobanSdk from "soroban-client";
import { isConnected } from "@stellar/freighter-api";
import isUndefined from "lodash/isUndefined";
import map from "lodash/map";
Expand Down Expand Up @@ -44,16 +43,10 @@ export const TransactionSigner = () => {
const networkPassphrase = network.current.networkPassphrase;
const isSoroban = useIsSoroban();

let TransactionBuilder, FeeBumpTransaction, Networks;
if (isSoroban) {
TransactionBuilder = SorobanSdk.TransactionBuilder;
FeeBumpTransaction = SorobanSdk.FeeBumpTransaction;
Networks = SorobanSdk.Networks;
} else {
TransactionBuilder = StellarSdk.TransactionBuilder;
FeeBumpTransaction = StellarSdk.FeeBumpTransaction;
Networks = StellarSdk.Networks;
}
let TransactionBuilder, FeeBumpTransaction, Networks: any;
TransactionBuilder = StellarSdk.TransactionBuilder;
FeeBumpTransaction = StellarSdk.FeeBumpTransaction;
Networks = StellarSdk.Networks;

const {
xdr,
Expand All @@ -65,7 +58,7 @@ export const TransactionSigner = () => {
} = transactionSigner;
let content;

if (validateTxXdr(xdr, isSoroban).result !== "success") {
if (validateTxXdr(xdr).result !== "success") {
content = (
<div className="so-back">
<div className="so-chunk">
Expand Down Expand Up @@ -389,7 +382,7 @@ export const TransactionSigner = () => {
<MultiPicker
component={SecretKeyPicker}
value={signers}
onUpdate={(value: string) => dispatch(setSecrets(value))}
onUpdate={(value) => dispatch(setSecrets(value))}
/>
</OptionsTablePair>
<OptionsTablePair label="BIP Path">
Expand Down
4 changes: 1 addition & 3 deletions src/views/XdrViewer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useDispatch } from "react-redux";
import * as StellarSdk from "stellar-sdk";
import * as SorobanSdk from "soroban-client";
import debounce from "lodash/debounce";
import functions from "lodash/functions";
import indexOf from "lodash/indexOf";
Expand Down Expand Up @@ -33,10 +32,9 @@ export const XdrViewer = () => {
const { fetchedSigners, input, type } = xdrViewer;
const { horizonURL, networkPassphrase } = network.current;
const isSoroban = useIsSoroban();
const sdk = isSoroban ? SorobanSdk : StellarSdk;
// Array of all the xdr types. Then, the most common ones appear at the top
// again for convenience
let xdrTypes = functions(sdk.xdr).sort();
let xdrTypes = functions(StellarSdk.xdr).sort();
xdrTypes = [
"TransactionEnvelope",
"TransactionResult",
Expand Down
Loading
Loading