Skip to content

Commit

Permalink
Make activity recognize proposal fees (#437)
Browse files Browse the repository at this point in the history
* Make activity recognize proposal fees

* feee -> fee
  • Loading branch information
panleone authored Nov 2, 2024
1 parent 97dd7eb commit 0a00445
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
5 changes: 5 additions & 0 deletions scripts/dashboard/Activity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ const txMap = computed(() => {
colour: 'white',
content: translation.activityUndelegated,
},
[HistoricalTxType.PROPOSAL_FEE]: {
icon: 'fa-minus',
colour: '#f93c4c',
content: 'Proposal Submission Fee',
},
[HistoricalTxType.UNKNOWN]: {
icon: 'fa-question',
colour: 'white',
Expand Down
1 change: 1 addition & 0 deletions scripts/historical_tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ export const HistoricalTxType = {
UNDELEGATION: 3,
RECEIVED: 4,
SENT: 5,
PROPOSAL_FEE: 6,
};
12 changes: 12 additions & 0 deletions scripts/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,18 @@ export function isP2EXC(dataBytes) {
dataBytes[25] == OP['CHECKSIG']
);
}

/**
* @param {Uint8Array} dataBytes - script as byte array
* @returns {boolean} true if the script is a proposal fee, false otherwise
*/
export function isProposalFee(dataBytes) {
return (
dataBytes.length == 34 &&
dataBytes[0] == OP['RETURN'] &&
dataBytes[1] == 32
);
}
/**
* Get address from the corresponding public key hash
* @param {Uint8Array} pkhBytes - public key hash
Expand Down
12 changes: 11 additions & 1 deletion scripts/transaction.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Buffer } from 'buffer';
import { bytesToNum, numToBytes, numToVarInt, parseWIF } from './encoding.js';
import { hexToBytes, bytesToHex, dSHA256 } from './utils.js';
import { OP } from './script.js';
import { isProposalFee, OP } from './script.js';
import { varIntToNum, deriveAddress } from './encoding.js';
import * as nobleSecp256k1 from '@noble/secp256k1';
import { cChainParams, SAPLING_TX_VERSION } from './chain_params.js';
Expand Down Expand Up @@ -170,6 +170,16 @@ export class Transaction {
);
}

isProposalFee() {
for (let out of this.vout) {
if (out.value === cChainParams.current.proposalFee) {
const dataBytes = hexToBytes(out.script);
if (isProposalFee(dataBytes)) return true;
}
}
return false;
}

/**
* @param {Transaction} tx - transaction we want to check
* @returns {boolean}
Expand Down
2 changes: 2 additions & 0 deletions scripts/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,8 @@ export class Wallet {
let type = HistoricalTxType.UNKNOWN;
if (tx.isCoinStake()) {
type = HistoricalTxType.STAKE;
} else if (tx.isProposalFee()) {
type = HistoricalTxType.PROPOSAL_FEE;
} else if (this.checkForUndelegations(tx)) {
type = HistoricalTxType.UNDELEGATION;
nAmount = getFilteredCredit(OutpointState.P2PKH) / COIN;
Expand Down

0 comments on commit 0a00445

Please sign in to comment.