Skip to content

Commit

Permalink
added automatic fee calculation for txAddressScript
Browse files Browse the repository at this point in the history
  • Loading branch information
deemru committed Dec 12, 2023
1 parent 4868119 commit 81f4d6f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/WavesKit.php
Original file line number Diff line number Diff line change
Expand Up @@ -2100,7 +2100,7 @@ public function txAddressScript( $script, $options = null )
$tx['senderPublicKey'] = isset( $options['senderPublicKey'] ) ? $options['senderPublicKey'] : $this->getPublicKey();
$tx['timestamp'] = isset( $options['timestamp'] ) ? $options['timestamp'] : $this->timestamp();
$tx['script'] = isset( $options['script'] ) ? $options['script'] : ( isset( $script ) ? 'base64:' . $script : null );
$tx['fee'] = isset( $options['fee'] ) ? $options['fee'] : 1000000;
$tx['fee'] = isset( $options['fee'] ) ? $options['fee'] : $this->getScriptFee( $tx );
return $tx;
}

Expand Down Expand Up @@ -2393,6 +2393,18 @@ private function getDataFee( $tx )
return 100000 * ( 1 + (int)( ( $size - 1 ) / 1024 ) );
}

private function getScriptFee( $tx )
{
if( !isset( $tx['script'] ) )
return 100000;

$size = strlen( $this->base64TxToBin( $tx['script'] ) );
if( $size === 0 )
return 100000;

return 100000 * ( 1 + (int)( ( $size - 1 ) / 1024 ) );
}

/**
* Gets transaction body
*
Expand Down

0 comments on commit 81f4d6f

Please sign in to comment.