From 81f4d6f72c76f1efbec28494b525763f8ad4612f Mon Sep 17 00:00:00 2001 From: Dmitrii Pichulin Date: Tue, 12 Dec 2023 15:09:41 +0300 Subject: [PATCH] added automatic fee calculation for txAddressScript --- src/WavesKit.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/WavesKit.php b/src/WavesKit.php index 835e282..f27da94 100644 --- a/src/WavesKit.php +++ b/src/WavesKit.php @@ -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; } @@ -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 *