Skip to content

Commit

Permalink
Fix in-game transfer polling (#2460)
Browse files Browse the repository at this point in the history
* Fix in-game transfer polling

* Set limit
  • Loading branch information
umairkhannn committed Apr 29, 2024
1 parent 55b677f commit c411c0b
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 31 deletions.
9 changes: 9 additions & 0 deletions lib/templates/cryptomodule.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,4 +485,13 @@ CryptoModule.prototype.returnWithdrawalFeeForAddress = function (
*/
CryptoModule.prototype.validateAddress = async function(address, ticker) { return true; }

/**
* return utxo
* @abstract
* @param {string} address to validate
* @param {string} ticker to for selected crypto
* @return {boolean} true/false
*/
CryptoModule.prototype.returnUtxo = async function(state = 'unspent', limit = 1000, order = 'DESC') { return true; }

module.exports = CryptoModule;
63 changes: 34 additions & 29 deletions mods/mixin/lib/mixinmodule.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class MixinModule extends CryptoModule {
this.balance_timestamp_last_fetched
);
this.balance_timestamp_last_fetched = new Date().getTime();
await this.mixin.fetchSafeUtxo(this.asset_id);
await this.mixin.fetchSafeUtxoBalance(this.asset_id);

this.app.connection.emit('header-update-balance');
}
Expand Down Expand Up @@ -343,58 +343,62 @@ class MixinModule extends CryptoModule {
//snapshot_datetime: Mon Feb 12 2024 16:31:44 GMT+0500 (Pakistan Standard Time)
//mixinmodule.js:454 received_datetime: Sun Sep 20 56111 06:01:14 GMT+0500 (Pakistan Standard Time)

let status = await this.mixin.fetchSafeSnapshots(this.asset_id, 1000, (d) => {
let status = await this.mixin.fetchUtxo('unspent', 100000, 'DESC', (d) => {

console.log('utxo: ', d);

if (d.length > 0) {

for (let i = (d.length - 1); i >= 0; i--) {
let row = d[i];
let snapshot_asset_id = row.asset_id;

console.log('*************************************')
console.log("snapshot response ///");
//compare timestamps
let snapshot_date = new Date(row.created_at);
let received_date = new Date(timestamp);

// filter out specific asset
if (snapshot_asset_id == this_self.asset_id) {
console.log('received_datetime - snapshot_datetime - diff : ',
received_date, snapshot_date, (snapshot_date - received_date));

console.log("assets matched ///");
if (snapshot_date - received_date > 0) {

let snapshot_opponent_id = row.opponent_id;
let snapshot_asset_id = row.asset_id;

console.log('snapshot_opponent_id: ', snapshot_opponent_id);
console.log('opponent_id: ', opponent_id);
console.log('*************************************');
console.log("snapshot response ///");

// filter out specific asset
if (snapshot_asset_id == this_self.asset_id) {

// filter out opponents
if ((opponent_id == snapshot_opponent_id)) {
console.log("assets matched ///");

console.log('opponent_id matched ////');
let senders = row.senders;

let snapshot_amount = Number(row.amount);
console.log('snapshot_opponent_id: ', senders);
console.log('opponent_id: ', opponent_id);
console.log('oponnent id exists:', senders.includes(opponent_id));


console.log('row.amount: ', row.amount);
console.log('snapshot_amount: ', snapshot_amount);
// filter out opponents
if (senders.includes(opponent_id)) {

// filter out deposit only
if (snapshot_amount > 0) {
console.log('opponent_id matched ////');

//compare timestamps
let snapshot_date = new Date(row.created_at);
let received_date = new Date(timestamp);

console.log('received_datetime - snapshot_datetime - diff : ', received_date, snapshot_date, (snapshot_date - received_date));
let snapshot_amount = Number(row.amount);
console.log('row.amount: ', row.amount);
console.log('snapshot_amount: ', snapshot_amount);

if ((snapshot_date - received_date > 0) && (snapshot_amount == amount)
&& (opponent_id == snapshot_opponent_id)){
if (snapshot_amount == amount){

console.log('match found ///');

return 1;
}

}
}

}

}

return 0;
Expand Down Expand Up @@ -470,6 +474,10 @@ class MixinModule extends CryptoModule {
return this.mixin.fetchSafeSnapshots(asset_id, records, callback);
}

async returnUtxo(state = 'unspent', limit = 500, order = 'DESC', callback = null) {
return await this.mixin.fetchUtxo(state, limit, order, callback);
}

async getMixinUser(address = '', callback = null) {
return await this.mixin.sendFetchUserTransaction({address: address}, function(res){
return callback(res);
Expand Down Expand Up @@ -551,13 +559,10 @@ class MixinModule extends CryptoModule {
asset_id: asset_id
},
function(res){
console.log('returning address 1////', res);
if (res.length > 0) {
address = res[0];
}
});

console.log('returning address 2////');
return address;
}

Expand Down
33 changes: 31 additions & 2 deletions mods/mixin/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class Mixin extends ModTemplate {
let pc = await this.app.wallet.returnPreferredCryptoTicker();
if (mixin_self.account_created !== 0 || (pc !== "SAITO" && pc !== "")) {
if (crypto_module.returnIsActivated()) {
await this.fetchSafeUtxo();
await this.fetchSafeUtxoBalance();
}
}
}
Expand Down Expand Up @@ -384,7 +384,7 @@ class Mixin extends ModTemplate {
}
}

async fetchSafeUtxo(asset_id){
async fetchSafeUtxoBalance(asset_id){
try {
let user = MixinApi({
keystore: {
Expand Down Expand Up @@ -441,6 +441,35 @@ class Mixin extends ModTemplate {
}
}

async fetchUtxo(state = 'unspent', limit = 100000, order = 'DESC', callback = null){
try {
let user = MixinApi({
keystore: {
app_id: this.mixin.user_id,
session_id: this.mixin.session_id,
pin_token_base64: this.mixin.tip_key_base64,
session_private_key: this.mixin.session_seed
},
});

let params = {
limit: limit,
state: state,
order: order,
};

let utxo_list = await user.utxo.safeOutputs(params);
console.log(`utxo_list ${state}:///`, utxo_list);

if (callback){
return callback(utxo_list);
}
} catch(err) {
console.error("ERROR: Mixin error return utxo: " + err);
return false;
}
}


async checkNetworkFee(asset_id){
try {
Expand Down

0 comments on commit c411c0b

Please sign in to comment.