upstream core updates, remove balance from asset obj
parent
edab13fd73
commit
d57285f1d1
|
@ -55,7 +55,7 @@
|
|||
branch = "master"
|
||||
name = "github.com/syscoin/btcd"
|
||||
packages = ["wire"]
|
||||
revision = "d354ec83e715af8c9ad056968609c8daec085aba"
|
||||
revision = "be589000d42661591ec4ca6e1fb781607f11980e"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
|
|
|
@ -1382,13 +1382,11 @@ func (w *Worker) GetAsset(asset string, page int, txsOnPage int, option AccountD
|
|||
AssetGuid: assetGuid,
|
||||
Symbol: string(dbAsset.AssetObj.Symbol),
|
||||
Contract: "0x" + hex.EncodeToString(dbAsset.AssetObj.Contract),
|
||||
Balance: (*bchain.Amount)(big.NewInt(dbAsset.AssetObj.Balance)),
|
||||
TotalSupply: (*bchain.Amount)(big.NewInt(dbAsset.AssetObj.TotalSupply)),
|
||||
MaxSupply: (*bchain.Amount)(big.NewInt(dbAsset.AssetObj.MaxSupply)),
|
||||
Decimals: int(dbAsset.AssetObj.Precision),
|
||||
UpdateCapabilityFlags: dbAsset.AssetObj.UpdateCapabilityFlags,
|
||||
NotaryKeyID: hex.EncodeToString(dbAsset.AssetObj.NotaryKeyID),
|
||||
AuxFeeKeyID: hex.EncodeToString(dbAsset.AssetObj.AuxFeeKeyID),
|
||||
},
|
||||
Paging: pg,
|
||||
UnconfirmedTxs: unconfirmedTxs,
|
||||
|
@ -1807,13 +1805,11 @@ func (w *Worker) GetAddressUtxo(address string, onlyConfirmed bool) (Utxos, erro
|
|||
AssetGuid: a.AssetInfo.AssetGuid,
|
||||
Symbol: string(dbAsset.AssetObj.Symbol),
|
||||
Contract: "0x" + hex.EncodeToString(dbAsset.AssetObj.Contract),
|
||||
Balance: (*bchain.Amount)(big.NewInt(dbAsset.AssetObj.Balance)),
|
||||
TotalSupply: (*bchain.Amount)(big.NewInt(dbAsset.AssetObj.TotalSupply)),
|
||||
MaxSupply: (*bchain.Amount)(big.NewInt(dbAsset.AssetObj.MaxSupply)),
|
||||
Decimals: int(dbAsset.AssetObj.Precision),
|
||||
UpdateCapabilityFlags: dbAsset.AssetObj.UpdateCapabilityFlags,
|
||||
NotaryKeyID: hex.EncodeToString(dbAsset.AssetObj.NotaryKeyID),
|
||||
AuxFeeKeyID: hex.EncodeToString(dbAsset.AssetObj.AuxFeeKeyID),
|
||||
}
|
||||
if len(dbAsset.AssetObj.PubData) > 0 {
|
||||
json.Unmarshal(dbAsset.AssetObj.PubData, &assetDetails.PubData)
|
||||
|
|
|
@ -682,13 +682,11 @@ func (w *Worker) GetXpubUtxo(xpub string, onlyConfirmed bool, gap int) (Utxos, e
|
|||
AssetGuid: a.AssetInfo.AssetGuid,
|
||||
Symbol: string(dbAsset.AssetObj.Symbol),
|
||||
Contract: "0x" + hex.EncodeToString(dbAsset.AssetObj.Contract),
|
||||
Balance: (*bchain.Amount)(big.NewInt(dbAsset.AssetObj.Balance)),
|
||||
TotalSupply: (*bchain.Amount)(big.NewInt(dbAsset.AssetObj.TotalSupply)),
|
||||
MaxSupply: (*bchain.Amount)(big.NewInt(dbAsset.AssetObj.MaxSupply)),
|
||||
Decimals: int(dbAsset.AssetObj.Precision),
|
||||
UpdateCapabilityFlags: dbAsset.AssetObj.UpdateCapabilityFlags,
|
||||
NotaryKeyID: hex.EncodeToString(dbAsset.AssetObj.NotaryKeyID),
|
||||
AuxFeeKeyID: hex.EncodeToString(dbAsset.AssetObj.AuxFeeKeyID),
|
||||
}
|
||||
if len(dbAsset.AssetObj.PubData) > 0 {
|
||||
json.Unmarshal(dbAsset.AssetObj.PubData, &assetDetails.PubData)
|
||||
|
|
|
@ -596,7 +596,7 @@ type TxAssetAddress struct {
|
|||
Txs []*TxAssetAddressIndex
|
||||
}
|
||||
type TxAssetAddressMap map[uint32]*TxAssetAddress
|
||||
|
||||
type AssetsMap map[uint32]int64
|
||||
// TxAddresses stores transaction inputs and outputs with amounts
|
||||
type TxAddresses struct {
|
||||
Version int32
|
||||
|
|
|
@ -510,6 +510,7 @@ func (d *RocksDB) processAddressesBitcoinType(block *bchain.Block, addresses bch
|
|||
blockTxIDs := make([][]byte, len(block.Txs))
|
||||
blockTxAddresses := make([]*bchain.TxAddresses, len(block.Txs))
|
||||
blockTxAssetAddresses := make(bchain.TxAssetAddressMap)
|
||||
mapAssetsIn := make(bchain.AssetsMap)
|
||||
// first process all outputs so that inputs can refer to txs in this block
|
||||
for txi := range block.Txs {
|
||||
tx := &block.Txs[txi]
|
||||
|
@ -524,10 +525,54 @@ func (d *RocksDB) processAddressesBitcoinType(block *bchain.Block, addresses bch
|
|||
blockTxIDs[txi] = btxID
|
||||
ta := bchain.TxAddresses{Version: tx.Version, Height: block.Height}
|
||||
ta.Outputs = make([]bchain.TxOutput, len(tx.Vout))
|
||||
ta.Inputs = make([]bchain.TxInput, len(tx.Vin))
|
||||
txAddressesMap[string(btxID)] = &ta
|
||||
blockTxAddresses[txi] = &ta
|
||||
maxAddrDescLen := d.chainParser.GetMaxAddrLength()
|
||||
assetsMask := d.chainParser.GetAssetsMaskFromVersion(tx.Version)
|
||||
// need to get input map for assets in asset send to manage total supply
|
||||
if(isAssetSendTx) {
|
||||
// save asset info in inputs
|
||||
for i, input := range tx.Vin {
|
||||
tai := &ta.Inputs[i]
|
||||
btxID, err := d.chainParser.PackTxid(input.Txid)
|
||||
if err != nil {
|
||||
// do not process inputs without input txid
|
||||
if err == bchain.ErrTxidMissing {
|
||||
continue
|
||||
}
|
||||
return err
|
||||
}
|
||||
stxID := string(btxID)
|
||||
ita, e := txAddressesMap[stxID]
|
||||
if !e {
|
||||
ita, err = d.getTxAddresses(btxID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if ita == nil {
|
||||
// allow parser to process unknown input, some coins may implement special handling, default is to log warning
|
||||
tai.AddrDesc = d.chainParser.GetAddrDescForUnknownInput(tx, i)
|
||||
continue
|
||||
}
|
||||
txAddressesMap[stxID] = ita
|
||||
d.cbs.txAddressesMiss++
|
||||
} else {
|
||||
d.cbs.txAddressesHit++
|
||||
}
|
||||
spentOutput := &ita.Outputs[int(input.Vout)]
|
||||
if spentOutput.AssetInfo != nil {
|
||||
assetIn, e := mapAssetsIn[spentOutput.AssetInfo.AssetGuid]
|
||||
if !e {
|
||||
assetIn = spentOutput.AssetInfo.ValueSat.Int64()
|
||||
mapAssetsIn[spentOutput.AssetInfo.AssetGuid] = assetIn
|
||||
} else {
|
||||
assetIn += spentOutput.AssetInfo.ValueSat.Int64()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for i, output := range tx.Vout {
|
||||
tao := &ta.Outputs[i]
|
||||
tao.ValueSat = output.ValueSat
|
||||
|
@ -604,7 +649,7 @@ func (d *RocksDB) processAddressesBitcoinType(block *bchain.Block, addresses bch
|
|||
}
|
||||
}
|
||||
if asset != nil {
|
||||
err = d.ConnectAssetOutput(asset, isActivate, isAssetTx, isAssetSendTx, assets)
|
||||
err = d.ConnectAssetOutput(asset, isActivate, isAssetTx, isAssetSendTx, assets, mapAssetsIn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -615,7 +660,6 @@ func (d *RocksDB) processAddressesBitcoinType(block *bchain.Block, addresses bch
|
|||
tx := &block.Txs[txi]
|
||||
spendingTxid := blockTxIDs[txi]
|
||||
ta := blockTxAddresses[txi]
|
||||
ta.Inputs = make([]bchain.TxInput, len(tx.Vin))
|
||||
logged := false
|
||||
assetsMask := d.chainParser.GetAssetsMaskFromVersion(tx.Version)
|
||||
for i, input := range tx.Vin {
|
||||
|
@ -642,21 +686,20 @@ func (d *RocksDB) processAddressesBitcoinType(block *bchain.Block, addresses bch
|
|||
}
|
||||
txAddressesMap[stxID] = ita
|
||||
d.cbs.txAddressesMiss++
|
||||
} else {
|
||||
d.cbs.txAddressesHit++
|
||||
}
|
||||
|
||||
if len(ita.Outputs) <= int(input.Vout) {
|
||||
glog.Warningf("rocksdb: height %d, tx %v, input tx %v vout %v is out of bounds of stored tx", block.Height, tx.Txid, input.Txid, input.Vout)
|
||||
continue
|
||||
}
|
||||
spentOutput := &ita.Outputs[int(input.Vout)]
|
||||
spentOutput := &ita.Outputs[int(input.Vout)]
|
||||
if spentOutput.Spent {
|
||||
glog.Warningf("rocksdb: height %d, tx %v, input tx %v vout %v is double spend", block.Height, tx.Txid, input.Txid, input.Vout)
|
||||
}
|
||||
|
||||
|
||||
tai.AddrDesc = spentOutput.AddrDesc
|
||||
tai.ValueSat = spentOutput.ValueSat
|
||||
|
||||
if spentOutput.AssetInfo != nil {
|
||||
tai.AssetInfo = &bchain.AssetInfo{AssetGuid: spentOutput.AssetInfo.AssetGuid, ValueSat: new(big.Int).Set(spentOutput.AssetInfo.ValueSat)}
|
||||
}
|
||||
|
@ -1017,8 +1060,11 @@ func (d *RocksDB) disconnectTxAddressesInputs(btxID []byte, inputs []bchain.DbOu
|
|||
getAddressBalance func(addrDesc bchain.AddressDescriptor) (*bchain.AddrBalance, error),
|
||||
addressFoundInTx func(addrDesc bchain.AddressDescriptor, btxID []byte) bool,
|
||||
assetFoundInTx func(asset uint32, btxID []byte) bool,
|
||||
assets map[uint32]*bchain.Asset, blockTxAssetAddresses bchain.TxAssetAddressMap) error {
|
||||
assets map[uint32]*bchain.Asset,
|
||||
blockTxAssetAddresses bchain.TxAssetAddressMap,
|
||||
mapAssetsIn bchain.AssetsMap) error {
|
||||
var err error
|
||||
isAssetSendTx := d.chainParser.IsAssetSendTx(txa.Version)
|
||||
for i, t := range txa.Inputs {
|
||||
if len(t.AddrDesc) > 0 {
|
||||
input := &inputs[i]
|
||||
|
@ -1073,6 +1119,15 @@ func (d *RocksDB) disconnectTxAddressesInputs(btxID []byte, inputs []bchain.DbOu
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if isAssetSendTx {
|
||||
assetIn, e := mapAssetsIn[t.AssetInfo.AssetGuid]
|
||||
if !e {
|
||||
assetIn = t.AssetInfo.ValueSat.Int64()
|
||||
mapAssetsIn[t.AssetInfo.AssetGuid] = assetIn
|
||||
} else {
|
||||
assetIn += t.AssetInfo.ValueSat.Int64()
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ad, _, _ := d.chainParser.GetAddressesFromAddrDesc(t.AddrDesc)
|
||||
|
@ -1085,7 +1140,8 @@ func (d *RocksDB) disconnectTxAddressesInputs(btxID []byte, inputs []bchain.DbOu
|
|||
}
|
||||
|
||||
func (d *RocksDB) disconnectTxAssetOutputs(txa *bchain.TxAddresses,
|
||||
assets map[uint32]*bchain.Asset) error {
|
||||
assets map[uint32]*bchain.Asset,
|
||||
mapAssetsIn bchain.AssetsMap) error {
|
||||
var asset *bchain.Asset = nil
|
||||
isAssetTx := d.chainParser.IsAssetTx(txa.Version)
|
||||
isAssetSendTx := d.chainParser.IsAssetSendTx(txa.Version)
|
||||
|
@ -1113,7 +1169,7 @@ func (d *RocksDB) disconnectTxAssetOutputs(txa *bchain.TxAddresses,
|
|||
}
|
||||
if asset != nil {
|
||||
isActivate := d.chainParser.IsAssetActivateTx(txa.Version)
|
||||
err := d.DisconnectAssetOutput(asset, isActivate, isAssetSendTx, assets)
|
||||
err := d.DisconnectAssetOutput(asset, isActivate, isAssetSendTx, assets, mapAssetsIn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1173,6 +1229,7 @@ func (d *RocksDB) disconnectBlock(height uint32, blockTxs []bchain.BlockTxs) err
|
|||
blockTxAssetAddresses := make(bchain.TxAssetAddressMap)
|
||||
balances := make(map[string]*bchain.AddrBalance)
|
||||
assets := make(map[uint32]*bchain.Asset)
|
||||
mapAssetsIn := make(bchain.AssetsMap)
|
||||
getAddressBalance := func(addrDesc bchain.AddressDescriptor) (*bchain.AddrBalance, error) {
|
||||
var err error
|
||||
s := string(addrDesc)
|
||||
|
@ -1237,7 +1294,7 @@ func (d *RocksDB) disconnectBlock(height uint32, blockTxs []bchain.BlockTxs) err
|
|||
continue
|
||||
}
|
||||
txAddresses[i] = txa
|
||||
if err := d.disconnectTxAddressesInputs(btxID, blockTxs[i].Inputs, txa, txAddressesToUpdate, getAddressBalance, addressFoundInTx, assetFoundInTx, assets, blockTxAssetAddresses); err != nil {
|
||||
if err := d.disconnectTxAddressesInputs(btxID, blockTxs[i].Inputs, txa, txAddressesToUpdate, getAddressBalance, addressFoundInTx, assetFoundInTx, assets, blockTxAssetAddresses, mapAssetsIn); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -1250,7 +1307,7 @@ func (d *RocksDB) disconnectBlock(height uint32, blockTxs []bchain.BlockTxs) err
|
|||
if err := d.disconnectTxAddressesOutputs(btxID, txa, getAddressBalance, addressFoundInTx, blockTxAssetAddresses); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := d.disconnectTxAssetOutputs(txa, assets); err != nil {
|
||||
if err := d.disconnectTxAssetOutputs(txa, assets, mapAssetsIn); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,10 +18,6 @@ type GetTxAssetsCallback func(txids []string) error
|
|||
|
||||
func (d *RocksDB) ConnectAssetOutputHelper(isActivate bool, asset *bchain.Asset, dBAsset *bchain.Asset) error {
|
||||
if !isActivate {
|
||||
if (asset.AssetObj.UpdateFlags & wire.ASSET_UPDATE_SUPPLY) != 0 {
|
||||
dBAsset.AssetObj.Balance += asset.AssetObj.Balance
|
||||
dBAsset.AssetObj.TotalSupply += asset.AssetObj.Balance
|
||||
}
|
||||
// logic follows core CheckAssetInputs()
|
||||
if (asset.AssetObj.UpdateFlags & wire.ASSET_UPDATE_DATA) != 0 {
|
||||
dBAsset.AssetObj.PubData = asset.AssetObj.PubData
|
||||
|
@ -55,20 +51,12 @@ func (d *RocksDB) ConnectAssetOutputHelper(isActivate bool, asset *bchain.Asset,
|
|||
dBAsset.AssetObj.UpdateFlags = dBAsset.AssetObj.UpdateFlags &^ wire.ASSET_UPDATE_NOTARY_DETAILS
|
||||
}
|
||||
}
|
||||
if (asset.AssetObj.UpdateFlags & wire.ASSET_UPDATE_AUXFEE_KEY) != 0 {
|
||||
dBAsset.AssetObj.AuxFeeKeyID = asset.AssetObj.AuxFeeKeyID
|
||||
if len(dBAsset.AssetObj.AuxFeeKeyID) > 0 {
|
||||
dBAsset.AssetObj.UpdateFlags |= wire.ASSET_UPDATE_AUXFEE_KEY
|
||||
} else {
|
||||
dBAsset.AssetObj.UpdateFlags = dBAsset.AssetObj.UpdateFlags &^ wire.ASSET_UPDATE_AUXFEE_KEY
|
||||
}
|
||||
}
|
||||
if (asset.AssetObj.UpdateFlags & wire.ASSET_UPDATE_AUXFEE_DETAILS) != 0 {
|
||||
if (asset.AssetObj.UpdateFlags & wire.ASSET_UPDATE_AUXFEE) != 0 {
|
||||
dBAsset.AssetObj.AuxFeeDetails = asset.AssetObj.AuxFeeDetails
|
||||
if len(dBAsset.AssetObj.AuxFeeDetails.AuxFees) > 0 {
|
||||
dBAsset.AssetObj.UpdateFlags |= wire.ASSET_UPDATE_AUXFEE_DETAILS
|
||||
if len(dBAsset.AssetObj.AuxFeeDetails.AuxFees) > 0 || len(dBAsset.AssetObj.AuxFeeDetails.AuxFeeKeyID) > 0 {
|
||||
dBAsset.AssetObj.UpdateFlags |= wire.ASSET_UPDATE_AUXFEE
|
||||
} else {
|
||||
dBAsset.AssetObj.UpdateFlags = dBAsset.AssetObj.UpdateFlags &^ wire.ASSET_UPDATE_AUXFEE_DETAILS
|
||||
dBAsset.AssetObj.UpdateFlags = dBAsset.AssetObj.UpdateFlags &^ wire.ASSET_UPDATE_AUXFEE
|
||||
}
|
||||
}
|
||||
if (asset.AssetObj.UpdateFlags & wire.ASSET_UPDATE_CAPABILITYFLAGS) != 0 {
|
||||
|
@ -80,7 +68,6 @@ func (d *RocksDB) ConnectAssetOutputHelper(isActivate bool, asset *bchain.Asset,
|
|||
}
|
||||
}
|
||||
} else {
|
||||
dBAsset.AssetObj.TotalSupply = asset.AssetObj.Balance
|
||||
dBAsset.AssetObj.UpdateFlags = asset.AssetObj.UpdateFlags
|
||||
// clear vout assets from storage
|
||||
dBAsset.AssetObj.Allocation.VoutAssets = make([]wire.AssetOutType, 0)
|
||||
|
@ -93,18 +80,6 @@ func (d *RocksDB) DisconnectAssetOutputHelper(asset *bchain.Asset, dBAsset *bcha
|
|||
if asset.AssetObj.UpdateFlags == 0 {
|
||||
return nil
|
||||
}
|
||||
if (asset.AssetObj.UpdateFlags & wire.ASSET_UPDATE_SUPPLY) != 0 {
|
||||
dBAsset.AssetObj.Balance -= asset.AssetObj.Balance
|
||||
if dBAsset.AssetObj.Balance < 0 {
|
||||
glog.Warningf("DisconnectAssetOutput balance is negative %v, setting to 0...", dBAsset.AssetObj.Balance)
|
||||
dBAsset.AssetObj.Balance = 0
|
||||
}
|
||||
dBAsset.AssetObj.TotalSupply -= asset.AssetObj.Balance
|
||||
if dBAsset.AssetObj.TotalSupply < 0 {
|
||||
glog.Warningf("DisconnectAssetOutput total supply is negative %v, setting to 0...", dBAsset.AssetObj.TotalSupply)
|
||||
dBAsset.AssetObj.TotalSupply = 0
|
||||
}
|
||||
}
|
||||
// logic follows core CheckAssetInputs()
|
||||
// undo data fields from last update
|
||||
// if fields changed then undo them using prev fields
|
||||
|
@ -141,20 +116,12 @@ func (d *RocksDB) DisconnectAssetOutputHelper(asset *bchain.Asset, dBAsset *bcha
|
|||
dBAsset.AssetObj.UpdateFlags = dBAsset.AssetObj.UpdateFlags &^ wire.ASSET_UPDATE_NOTARY_DETAILS
|
||||
}
|
||||
}
|
||||
if (asset.AssetObj.UpdateFlags & wire.ASSET_UPDATE_AUXFEE_KEY) != 0 {
|
||||
dBAsset.AssetObj.AuxFeeKeyID = asset.AssetObj.PrevAuxFeeKeyID
|
||||
if len(dBAsset.AssetObj.AuxFeeKeyID) > 0 {
|
||||
dBAsset.AssetObj.UpdateFlags |= wire.ASSET_UPDATE_AUXFEE_KEY
|
||||
} else {
|
||||
dBAsset.AssetObj.UpdateFlags = dBAsset.AssetObj.UpdateFlags &^ wire.ASSET_UPDATE_AUXFEE_KEY
|
||||
}
|
||||
}
|
||||
if (asset.AssetObj.UpdateFlags & wire.ASSET_UPDATE_AUXFEE_DETAILS) != 0 {
|
||||
if (asset.AssetObj.UpdateFlags & wire.ASSET_UPDATE_AUXFEE) != 0 {
|
||||
dBAsset.AssetObj.AuxFeeDetails = asset.AssetObj.PrevAuxFeeDetails
|
||||
if len(dBAsset.AssetObj.AuxFeeDetails.AuxFees) > 0 {
|
||||
dBAsset.AssetObj.UpdateFlags |= wire.ASSET_UPDATE_AUXFEE_DETAILS
|
||||
if len(dBAsset.AssetObj.AuxFeeDetails.AuxFees) > 0 || len(dBAsset.AssetObj.AuxFeeDetails.AuxFeeKeyID) > 0 {
|
||||
dBAsset.AssetObj.UpdateFlags |= wire.ASSET_UPDATE_AUXFEE
|
||||
} else {
|
||||
dBAsset.AssetObj.UpdateFlags = dBAsset.AssetObj.UpdateFlags &^ wire.ASSET_UPDATE_AUXFEE_DETAILS
|
||||
dBAsset.AssetObj.UpdateFlags = dBAsset.AssetObj.UpdateFlags &^ wire.ASSET_UPDATE_AUXFEE
|
||||
}
|
||||
}
|
||||
if (asset.AssetObj.UpdateFlags & wire.ASSET_UPDATE_CAPABILITYFLAGS) != 0 {
|
||||
|
@ -206,7 +173,7 @@ func (d *RocksDB) ConnectAllocationOutput(addrDesc* bchain.AddressDescriptor, he
|
|||
return nil
|
||||
}
|
||||
|
||||
func (d *RocksDB) ConnectAssetOutput(asset *bchain.Asset, isActivate bool, isAssetTx bool, isAssetSendTx bool, assets map[uint32]*bchain.Asset) error {
|
||||
func (d *RocksDB) ConnectAssetOutput(asset *bchain.Asset, isActivate bool, isAssetTx bool, isAssetSendTx bool, assets map[uint32]*bchain.Asset, mapAssetsIn bchain.AssetsMap) error {
|
||||
var dBAsset* bchain.Asset = nil
|
||||
var err error
|
||||
assetGuid := asset.AssetObj.Allocation.VoutAssets[0].AssetGuid
|
||||
|
@ -229,15 +196,16 @@ func (d *RocksDB) ConnectAssetOutput(asset *bchain.Asset, isActivate bool, isAss
|
|||
}
|
||||
} else if isAssetSendTx {
|
||||
// tally total amount and subtract from asset
|
||||
valueSat := int64(0)
|
||||
valueSatOut := int64(0)
|
||||
for _, v := range asset.AssetObj.Allocation.VoutAssets[0].Values {
|
||||
valueSat += v.ValueSat
|
||||
valueSatOut += v.ValueSat
|
||||
}
|
||||
dBAsset.AssetObj.Balance -= valueSat
|
||||
if dBAsset.AssetObj.Balance < 0 {
|
||||
glog.Warningf("ConnectAssetOutput balance is negative %v, setting to 0...", dBAsset.AssetObj.Balance)
|
||||
dBAsset.AssetObj.Balance = 0
|
||||
valueSatIn, e := mapAssetsIn[assetGuid]
|
||||
if !e {
|
||||
return errors.New(fmt.Sprint("ConnectAssetOutput asset input not found " , assetGuid))
|
||||
}
|
||||
dBAsset.AssetObj.TotalSupply += (valueSatOut - valueSatIn)
|
||||
dBAsset.AssetObj.UpdateFlags |= wire.ASSET_UPDATE_SUPPLY
|
||||
}
|
||||
assets[assetGuid] = dBAsset
|
||||
} else {
|
||||
|
@ -258,7 +226,7 @@ func (d *RocksDB) DisconnectAllocationOutput(addrDesc *bchain.AddressDescriptor,
|
|||
}
|
||||
return nil
|
||||
}
|
||||
func (d *RocksDB) DisconnectAssetOutput(asset *bchain.Asset, isActivate bool, isAssetSendTx bool, assets map[uint32]*bchain.Asset) error {
|
||||
func (d *RocksDB) DisconnectAssetOutput(asset *bchain.Asset, isActivate bool, isAssetSendTx bool, assets map[uint32]*bchain.Asset, mapAssetsIn bchain.AssetsMap) error {
|
||||
assetGuid := asset.AssetObj.Allocation.VoutAssets[0].AssetGuid
|
||||
dBAsset, err := d.GetAsset(assetGuid, assets)
|
||||
if dBAsset == nil || err != nil {
|
||||
|
@ -270,11 +238,22 @@ func (d *RocksDB) DisconnectAssetOutput(asset *bchain.Asset, isActivate bool, is
|
|||
if !isActivate {
|
||||
if isAssetSendTx {
|
||||
// tally total amount and add to asset
|
||||
valueSat := int64(0)
|
||||
valueSatOut := int64(0)
|
||||
for _, v := range asset.AssetObj.Allocation.VoutAssets[0].Values {
|
||||
valueSat += v.ValueSat
|
||||
valueSatOut += v.ValueSat
|
||||
}
|
||||
valueSatIn, e := mapAssetsIn[assetGuid]
|
||||
if !e {
|
||||
return errors.New(fmt.Sprint("DisconnectAssetOutput asset input not found " , assetGuid))
|
||||
}
|
||||
dBAsset.AssetObj.TotalSupply -= (valueSatOut - valueSatIn)
|
||||
if dBAsset.AssetObj.TotalSupply < 0 {
|
||||
glog.Warningf("DisconnectAssetOutput total supply is negative %v, setting to 0...", dBAsset.AssetObj.TotalSupply)
|
||||
dBAsset.AssetObj.TotalSupply = 0
|
||||
}
|
||||
if dBAsset.AssetObj.TotalSupply == 0 {
|
||||
dBAsset.AssetObj.UpdateFlags = dBAsset.AssetObj.UpdateFlags &^ wire.ASSET_UPDATE_SUPPLY
|
||||
}
|
||||
dBAsset.AssetObj.Balance += valueSat
|
||||
} else {
|
||||
err = d.DisconnectAssetOutputHelper(asset, dBAsset)
|
||||
if err != nil {
|
||||
|
|
|
@ -131,11 +131,8 @@ func verifyAfterSyscoinTypeBlock1(t *testing.T, d *RocksDB, afterDisconnect bool
|
|||
if dBAsset.AssetObj.UpdateFlags != 133 {
|
||||
t.Fatal(fmt.Sprint("Block1: Property mismatch dBAsset.AssetObj.UpdateFlags: ", dBAsset.AssetObj.UpdateFlags , ". Expected: 133"))
|
||||
}
|
||||
if dBAsset.AssetObj.Balance != 10000000000 {
|
||||
t.Fatal(fmt.Sprint("Block1: Property mismatch dBAsset.AssetObj.Balance: ", dBAsset.AssetObj.Balance , ". Expected: 10000000000"))
|
||||
}
|
||||
if dBAsset.AssetObj.TotalSupply != 10000000000 {
|
||||
t.Fatal(fmt.Sprint("Block1: Property mismatch dBAsset.AssetObj.TotalSupply: ", dBAsset.AssetObj.TotalSupply , ". Expected: 10000000000"))
|
||||
if dBAsset.AssetObj.TotalSupply != 0 {
|
||||
t.Fatal(fmt.Sprint("Block1: Property mismatch dBAsset.AssetObj.TotalSupply: ", dBAsset.AssetObj.TotalSupply , ". Expected: 0"))
|
||||
}
|
||||
if dBAsset.AssetObj.MaxSupply != 100000000000 {
|
||||
t.Fatal(fmt.Sprint("Block1: Property mismatch dBAsset.AssetObj.MaxSupply: ", dBAsset.AssetObj.MaxSupply , ". Expected: 100000000000"))
|
||||
|
@ -233,11 +230,8 @@ func verifyAfterSyscoinTypeBlock2(t *testing.T, d *RocksDB) {
|
|||
if dBAsset.AssetObj.UpdateFlags != 135 {
|
||||
t.Fatal(fmt.Sprint("Block2: Property mismatch dBAsset.AssetObj.UpdateFlags: ", dBAsset.AssetObj.UpdateFlags , ". Expected: 135"))
|
||||
}
|
||||
if dBAsset.AssetObj.Balance != 52000000000 {
|
||||
t.Fatal(fmt.Sprint("Block2: Property mismatch dBAsset.AssetObj.Balance: ", dBAsset.AssetObj.Balance , ". Expected: 52000000000"))
|
||||
}
|
||||
if dBAsset.AssetObj.TotalSupply != 52000000000 {
|
||||
t.Fatal(fmt.Sprint("Block2: Property mismatch dBAsset.AssetObj.TotalSupply: ", dBAsset.AssetObj.TotalSupply , ". Expected: 52000000000"))
|
||||
if dBAsset.AssetObj.TotalSupply != 0 {
|
||||
t.Fatal(fmt.Sprint("Block2: Property mismatch dBAsset.AssetObj.TotalSupply: ", dBAsset.AssetObj.TotalSupply , ". Expected: 0"))
|
||||
}
|
||||
if dBAsset.AssetObj.MaxSupply != 100000000000 {
|
||||
t.Fatal(fmt.Sprint("Block2: Property mismatch dBAsset.AssetObj.MaxSupply: ", dBAsset.AssetObj.MaxSupply , ". Expected: 100000000000"))
|
||||
|
|
|
@ -631,13 +631,11 @@ func (s *SocketIoServer) getAssetHistory(asset string, opts *assetOpts) (res res
|
|||
AssetGuid: assetGuid,
|
||||
Symbol: string(dbAsset.AssetObj.Symbol),
|
||||
Contract: "0x" + hex.EncodeToString(dbAsset.AssetObj.Contract),
|
||||
Balance: (*bchain.Amount)(big.NewInt(dbAsset.AssetObj.Balance)),
|
||||
TotalSupply: (*bchain.Amount)(big.NewInt(dbAsset.AssetObj.TotalSupply)),
|
||||
MaxSupply: (*bchain.Amount)(big.NewInt(dbAsset.AssetObj.MaxSupply)),
|
||||
Decimals: int(dbAsset.AssetObj.Precision),
|
||||
UpdateCapabilityFlags: dbAsset.AssetObj.UpdateCapabilityFlags,
|
||||
NotaryKeyID: hex.EncodeToString(dbAsset.AssetObj.NotaryKeyID),
|
||||
AuxFeeKeyID: hex.EncodeToString(dbAsset.AssetObj.AuxFeeKeyID),
|
||||
|
||||
}
|
||||
if len(dbAsset.AssetObj.AuxFeeKeyID) > 0 {
|
||||
|
|
Loading…
Reference in New Issue