Skip to content

Commit 81a9016

Browse files
authored
[N4] Unify RPC logic and fix size check (#937)
* unify logic and fix length * fix usings
1 parent 5116e96 commit 81a9016

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

plugins/RpcServer/RpcServer.Wallet.cs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -373,13 +373,7 @@ protected internal virtual JToken SendFrom(UInt160 assetId, Address from, Addres
373373
if (!transContext.Completed) return transContext.ToJson();
374374

375375
tx.Witnesses = transContext.GetWitnesses();
376-
if (tx.Size > 1024)
377-
{
378-
long calFee = tx.Size * NativeContract.Policy.GetFeePerByte(snapshot) + 100000;
379-
if (tx.NetworkFee < calFee)
380-
tx.NetworkFee = calFee;
381-
}
382-
(tx.NetworkFee <= settings.MaxFee).True_Or(RpcError.WalletFeeLimit);
376+
EnsureNetworkFee(snapshot, tx);
383377
return SignAndRelay(snapshot, tx);
384378
}
385379

@@ -490,13 +484,7 @@ protected internal virtual JToken SendMany(JArray _params)
490484
if (!transContext.Completed) return transContext.ToJson();
491485

492486
tx.Witnesses = transContext.GetWitnesses();
493-
if (tx.Size > 1024)
494-
{
495-
long calFee = tx.Size * NativeContract.Policy.GetFeePerByte(snapshot) + 100000;
496-
if (tx.NetworkFee < calFee)
497-
tx.NetworkFee = calFee;
498-
}
499-
(tx.NetworkFee <= settings.MaxFee).True_Or(RpcError.WalletFeeLimit);
487+
EnsureNetworkFee(snapshot, tx);
500488
return SignAndRelay(snapshot, tx);
501489
}
502490

@@ -553,16 +541,18 @@ protected internal virtual JToken SendToAddress(UInt160 assetId, Address to, str
553541
return transContext.ToJson();
554542

555543
tx.Witnesses = transContext.GetWitnesses();
556-
if (tx.Size > 1024)
557-
{
558-
long calFee = tx.Size * NativeContract.Policy.GetFeePerByte(snapshot) + 100000;
559-
if (tx.NetworkFee < calFee)
560-
tx.NetworkFee = calFee;
561-
}
562-
(tx.NetworkFee <= settings.MaxFee).True_Or(RpcError.WalletFeeLimit);
544+
EnsureNetworkFee(snapshot, tx);
563545
return SignAndRelay(snapshot, tx);
564546
}
565547

548+
private void EnsureNetworkFee(StoreCache snapshot, Transaction tx)
549+
{
550+
long calFee = tx.Size * NativeContract.Policy.GetFeePerByte(snapshot) + 100000;
551+
if (tx.NetworkFee < calFee)
552+
tx.NetworkFee = calFee;
553+
(tx.NetworkFee <= settings.MaxFee).True_Or(RpcError.WalletFeeLimit);
554+
}
555+
566556
/// <summary>
567557
/// Cancels an unconfirmed transaction.
568558
/// <para>Request format:</para>

0 commit comments

Comments
 (0)