fix: caller set as id of calling contract for internal writes
This commit is contained in:
committed by
Piotr Pędziwiatr
parent
1663bcbaeb
commit
5791c81b4f
@@ -10,6 +10,7 @@ export async function handle(state, action) {
|
||||
const _msgSender = action.caller;
|
||||
|
||||
if (_input.function === 'stake') {
|
||||
console.log('stake:', _msgSender);
|
||||
const amount = _input.amount;
|
||||
if (amount < _minimumStake) {
|
||||
throw new ContractError(`You must stake at least ${_minimumStake} tokens`);
|
||||
@@ -21,6 +22,8 @@ export async function handle(state, action) {
|
||||
throw new ContractError('Cannot stake more token than you hold unstaked');
|
||||
}
|
||||
|
||||
console.log('allowances', tokenState.allowances);
|
||||
|
||||
if (!tokenState.allowances[_msgSender]) {
|
||||
throw new ContractError('Caller must increase their allowance');
|
||||
}
|
||||
|
||||
@@ -21,6 +21,10 @@ export function handle(state, action) {
|
||||
if (_input.function === 'approve') {
|
||||
const spender = _input.spender;
|
||||
const amount = _input.amount;
|
||||
console.log('approve:', {
|
||||
_msgSender,
|
||||
spender
|
||||
});
|
||||
|
||||
if (!_allowances[_msgSender]) {
|
||||
_allowances[_msgSender] = {};
|
||||
@@ -65,7 +69,13 @@ export function handle(state, action) {
|
||||
const amount = _input.amount;
|
||||
|
||||
const currentAllowance = _allowances[sender][_msgSender];
|
||||
if (currentAllowance < amount) {
|
||||
console.log('transferFrom msgSender:', {
|
||||
sender,
|
||||
_msgSender,
|
||||
currentAllowance
|
||||
});
|
||||
|
||||
if (currentAllowance === undefined || currentAllowance < amount) {
|
||||
throw new ContractError(`Transfer amount exceeds allowance`);
|
||||
}
|
||||
|
||||
|
||||
@@ -139,6 +139,10 @@ describe('Testing internal writes', () => {
|
||||
});
|
||||
|
||||
it('should approve for staking contract', async () => {
|
||||
console.log('Wallet addresss', walletAddress);
|
||||
console.log('token address', tokenContractTxId);
|
||||
console.log('staking contract address', stakingContractTxId);
|
||||
|
||||
await tokenContract.writeInteraction({
|
||||
function: 'approve',
|
||||
spender: stakingContractTxId,
|
||||
@@ -154,6 +158,7 @@ describe('Testing internal writes', () => {
|
||||
});
|
||||
|
||||
it('should stake tokens', async () => {
|
||||
console.log('Wallet addresss', walletAddress);
|
||||
await stakingContract.writeInteraction({
|
||||
function: 'stake',
|
||||
amount: 1000
|
||||
|
||||
@@ -466,7 +466,7 @@ export class HandlerBasedContract<State> implements Contract<State> {
|
||||
|
||||
const interaction: ContractInteraction<Input> = {
|
||||
input,
|
||||
caller: executionContext.caller
|
||||
caller: this.callingContract.txId()//executionContext.caller
|
||||
};
|
||||
|
||||
const interactionData: InteractionData<Input> = {
|
||||
|
||||
Reference in New Issue
Block a user