-
Notifications
You must be signed in to change notification settings - Fork 14
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
feat: process tx after push #813
base: master
Are you sure you want to change the base?
Changes from 12 commits
94e96e8
8b978c4
8d9b598
b55524f
7882a17
457dc12
32f21f6
cfe92eb
d153f63
6a23eb6
53b0eb1
a72b608
f48b51f
e893e7c
9abd019
e5cef34
3371335
d8f50a0
aabb513
2073342
2723011
d461387
dddbedf
c16860f
9dda85d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,9 @@ | |
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import { AxiosResponse } from 'axios'; | ||
import { createRequestInstance } from './axiosInstance'; | ||
import { transformJsonBigIntResponse } from '../utils/bigint'; | ||
import { TransactionSchema, transactionSchema } from './schemas/txApi'; | ||
import { transactionSchema } from './schemas/txApi'; | ||
|
||
/** | ||
* Api calls for transaction | ||
|
@@ -78,7 +77,7 @@ const txApi = { | |
* @memberof ApiTransaction | ||
* @inner | ||
*/ | ||
getTransaction(id, resolve): Promise<void | AxiosResponse<TransactionSchema>> { | ||
getTransaction(id, resolve): Promise<void> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
const data = { id }; | ||
return this.getTransactionBase(data, resolve, transactionSchema); | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,8 @@ import { | |
} from '../types'; | ||
import Transaction from '../models/transaction'; | ||
import { bestUtxoSelection } from '../utils/utxo'; | ||
import { addCreatedTokenFromTx } from '../utils/storage'; | ||
import CreateTokenTransaction from '../models/create_token_transaction'; | ||
|
||
export interface ISendInput { | ||
txId: string; | ||
|
@@ -422,6 +424,23 @@ export default class SendTransaction extends EventEmitter { | |
throw new WalletError(ErrorMessages.TRANSACTION_IS_NULL); | ||
} | ||
this.transaction.updateHash(); | ||
if (this.storage) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the core of the PR. When we push a transaction we need to convert it from a If we are creating a token we should also add it to the tokens here because the fullnode may not know that this token exists when we ask for the name and symbol for this UID. It also saves us from making an extraneous API call. |
||
// Add transaction to storage and process storage | ||
(async (storage: IStorage, transaction: Transaction) => { | ||
// Get the transaction as a history object | ||
const historyTx = await transactionUtils.convertTransactionToHistoryTx( | ||
transaction, | ||
storage | ||
); | ||
// Add transaction to storage | ||
await storage.addTx(historyTx); | ||
// Add token from a create token transaction to the storage | ||
// This just returns if the transaction is not a CREATE_TOKEN_TX | ||
await addCreatedTokenFromTx(transaction as CreateTokenTransaction, storage); | ||
// Process new transaction | ||
await storage.processNewTx(historyTx); | ||
})(this.storage, this.transaction); | ||
} | ||
this.emit('send-tx-success', this.transaction); | ||
resolve(this.transaction); | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,8 +120,12 @@ export class Storage implements IStorage { | |
* Set the native token config on the store | ||
*/ | ||
async saveNativeToken(): Promise<void> { | ||
if ((await this.store.getToken(NATIVE_TOKEN_UID)) === null) { | ||
await this.store.saveToken(this.getNativeTokenData()); | ||
await this.addToken(this.getNativeTokenData()); | ||
} | ||
|
||
async addToken(data: ITokenData): Promise<void> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing docstring There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added docstring |
||
if ((await this.store.getToken(data.uid)) === null) { | ||
await this.store.saveToken(data); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
HistorySyncFunction, | ||
WalletType, | ||
IUtxo, | ||
ITokenData, | ||
} from '../types'; | ||
import walletApi from '../api/wallet'; | ||
import helpers from './helpers'; | ||
|
@@ -35,8 +36,10 @@ | |
NANO_CONTRACTS_VERSION, | ||
LOAD_WALLET_MAX_RETRY, | ||
LOAD_WALLET_RETRY_SLEEP, | ||
CREATE_TOKEN_TX_VERSION, | ||
} from '../constants'; | ||
import { AddressHistorySchema, GeneralTokenInfoSchema } from '../api/schemas/wallet'; | ||
import CreateTokenTransaction from '../models/create_token_transaction'; | ||
|
||
/** | ||
* Get history sync method for a given mode | ||
|
@@ -515,8 +518,12 @@ | |
|
||
const { name, symbol } = response; | ||
const tokenData = { uid, name, symbol }; | ||
// saveToken will ignore the meta and save only the token config | ||
await store.saveToken(tokenData); | ||
|
||
const storeToken = await store.getToken(uid); | ||
if (storeToken === null) { | ||
// saveToken will ignore the meta and save only the token config | ||
await store.saveToken(tokenData); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this the same as the new There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, changed to use the storage method |
||
} | ||
} | ||
} | ||
|
@@ -890,3 +897,24 @@ | |
// Remove utxo from locked utxos so that it is not processed again | ||
await store.unlockUtxo(lockedUtxo); | ||
} | ||
|
||
export async function addCreatedTokenFromTx( | ||
tx: CreateTokenTransaction, | ||
storage: IStorage | ||
): Promise<void> { | ||
if (tx.version !== CREATE_TOKEN_TX_VERSION) { | ||
return; | ||
} | ||
|
||
if (!tx.hash) { | ||
throw new Error('Cannot infer UID from transaction without hash'); | ||
tuliomir marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
const tokenInfo: ITokenData = { | ||
uid: tx.hash, | ||
name: tx.name, | ||
symbol: tx.symbol, | ||
}; | ||
|
||
await storage.addToken(tokenInfo); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated to line
All changes in this file are related to typing, some jsdoc types that were not converted into ts types.
This removes some typing alerts from the tests.
Obs: We don't have alerts on the CI because we exclude tests from tsc