Skip to content

Commit

Permalink
Fix Salvium payment error
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaolin1579 committed Oct 17, 2024
1 parent 6ad7d6e commit 342f64a
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 30 deletions.
13 changes: 13 additions & 0 deletions src/Miningcore/Blockchain/Cryptonote/CryptonoteConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,16 @@ public static class CryptonoteWalletCommands
public const string SplitIntegratedAddress = "split_integrated_address";
public const string Store = "store";
}

public enum SalviumTransactionType
{
Unset = 0,
Miner = 1,
Protocol = 2,
Transfer = 3,
Convert = 4,
Burn = 5,
Stake = 6,
Return = 7,
Max = 7
}
115 changes: 85 additions & 30 deletions src/Miningcore/Blockchain/Cryptonote/CryptonotePayoutHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ private async Task<bool> EnsureBalance(decimal requiredAmount, CryptonoteCoinTem
decimal unlockedBalance = 0.0m;
decimal balance = 0.0m;

// Not all Cryptonote coins are equal
// not all Cryptonote coins are equal
switch(coin.Symbol)
{
case "SAL":
case "ZEPH":
var responseBalances = await rpcClientWallet.ExecuteAsync<GetBalancesResponse>(logger, CryptonoteWalletCommands.GetBalance, ct);

Expand Down Expand Up @@ -198,24 +199,51 @@ private async Task<bool> PayoutBatch(Balance[] balances, CancellationToken ct)
if(!await EnsureBalance(balances.Sum(x => x.Amount), coin, ct))
return false;

// build request
var request = new TransferRequest
TransferRequest request;
// not all Cryptonote coins are equal
switch(coin.Symbol)
{
Destinations = balances
.Where(x => x.Amount > 0)
.Select(x =>
case "SAL":
// build request
request = new TransferRequest
{
ExtractAddressAndPaymentId(x.Address, out var address, out _);

return new TransferDestination
{
Address = address,
Amount = (ulong) Math.Floor(x.Amount * coin.SmallestUnit)
};
}).ToArray(),

GetTxKey = true
};
Destinations = balances
.Where(x => x.Amount > 0)
.Select(x =>
{
ExtractAddressAndPaymentId(x.Address, out var address, out _);
return new TransferDestination
{
Address = address,
Amount = (ulong) Math.Floor(x.Amount * coin.SmallestUnit),
AssetType = coin.Symbol
};
}).ToArray(),
TransactionType = (uint) SalviumTransactionType.Transfer,
SourceAsset = coin.Symbol,
DestinationAsset = coin.Symbol,
GetTxKey = true
};
break;
default:
// build request
request = new TransferRequest
{
Destinations = balances
.Where(x => x.Amount > 0)
.Select(x =>
{
ExtractAddressAndPaymentId(x.Address, out var address, out _);
return new TransferDestination
{
Address = address,
Amount = (ulong) Math.Floor(x.Amount * coin.SmallestUnit)
};
}).ToArray(),
GetTxKey = true
};
break;
}

if(request.Destinations.Length == 0)
return true;
Expand Down Expand Up @@ -276,20 +304,47 @@ private async Task<bool> PayoutToPaymentId(Balance balance, CancellationToken ct
if(!await EnsureBalance(balance.Amount, coin, ct))
return false;

// build request
var request = new TransferRequest
TransferRequest request;
// not all Cryptonote coins are equal
switch(coin.Symbol)
{
Destinations = new[]
{
new TransferDestination
case "SAL":
// build request
request = new TransferRequest
{
Address = address,
Amount = (ulong) Math.Floor(balance.Amount * coin.SmallestUnit)
}
},
PaymentId = paymentId,
GetTxKey = true
};
Destinations = new[]
{
new TransferDestination
{
Address = address,
Amount = (ulong) Math.Floor(balance.Amount * coin.SmallestUnit),
AssetType = coin.Symbol
}
},
TransactionType = (uint) SalviumTransactionType.Transfer,
PaymentId = paymentId,
SourceAsset = coin.Symbol,
DestinationAsset = coin.Symbol,
GetTxKey = true
};
break;
default:
// build request
request = new TransferRequest
{
Destinations = new[]
{
new TransferDestination
{
Address = address,
Amount = (ulong) Math.Floor(balance.Amount * coin.SmallestUnit)
}
},
PaymentId = paymentId,
GetTxKey = true
};
break;
}

if(!isIntegratedAddress)
request.PaymentId = paymentId;
Expand Down Expand Up @@ -433,7 +488,7 @@ public async Task<Block[]> ClassifyBlocksAsync(IMiningPool pool, Block[] blocks,
block.Status = BlockStatus.Confirmed;
block.ConfirmationProgress = 1;

// Not all Cryptonote coins are equal
// not all Cryptonote coins are equal
switch(coin.Symbol)
{
case "ZEPH":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ public class TransferDestination
{
public string Address { get; set; }
public ulong Amount { get; set; }

// Salvium
/// <summary>
/// Define the type of coin to be received
/// </summary>
[JsonProperty("asset_type", NullValueHandling = NullValueHandling.Ignore)]
public string AssetType { get; set; }
}

public class TransferRequest
Expand Down Expand Up @@ -51,4 +58,23 @@ public class TransferRequest
/// </summary>
[JsonProperty("unlock_time")]
public uint UnlockTime { get; set; }

// Salvium
/// <summary>
/// Define the type of transaction
/// </summary>
[JsonProperty("tx_type", NullValueHandling = NullValueHandling.Ignore)]
public uint? TransactionType { get; set; }
// Salvium
/// <summary>
/// Define the type of coin to be sent
/// </summary>
[JsonProperty("source_asset", NullValueHandling = NullValueHandling.Ignore)]
public string SourceAsset { get; set; }
// Salvium
/// <summary>
/// Define the type of coin to be received
/// </summary>
[JsonProperty("dest_asset", NullValueHandling = NullValueHandling.Ignore)]
public string DestinationAsset { get; set; }
}

0 comments on commit 342f64a

Please sign in to comment.