Commit 91bf5af7 authored by Neposyda's avatar Neposyda
Browse files

complex transfer finished

parent c80a191b
This diff is collapsed.
This diff is collapsed.
// Code generated - DO NOT EDIT.
// This file is a generated binding and any manual changes will be lost.
package oracle
import (
"errors"
"math/big"
"strings"
ethereum "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/event"
)
// Reference imports to suppress errors if they are not otherwise used.
var (
_ = errors.New
_ = big.NewInt
_ = strings.NewReader
_ = ethereum.NotFound
_ = bind.Bind
_ = common.Big1
_ = types.BloomLookup
_ = event.NewSubscription
)
// OracleMetaData contains all meta data concerning the Oracle contract.
var OracleMetaData = &bind.MetaData{
ABI: "[{\"inputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"baseAggr\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"quoteAggr\",\"type\":\"string\"}],\"name\":\"getDerivedPrice\",\"outputs\":[{\"internalType\":\"int256\",\"name\":\"\",\"type\":\"int256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"aggregator\",\"type\":\"string\"}],\"name\":\"getLatestPrice\",\"outputs\":[{\"internalType\":\"int256\",\"name\":\"\",\"type\":\"int256\"},{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]",
}
// OracleABI is the input ABI used to generate the binding from.
// Deprecated: Use OracleMetaData.ABI instead.
var OracleABI = OracleMetaData.ABI
// Oracle is an auto generated Go binding around an Ethereum contract.
type Oracle struct {
OracleCaller // Read-only binding to the contract
OracleTransactor // Write-only binding to the contract
OracleFilterer // Log filterer for contract events
}
// OracleCaller is an auto generated read-only Go binding around an Ethereum contract.
type OracleCaller struct {
contract *bind.BoundContract // Generic contract wrapper for the low level calls
}
// OracleTransactor is an auto generated write-only Go binding around an Ethereum contract.
type OracleTransactor struct {
contract *bind.BoundContract // Generic contract wrapper for the low level calls
}
// OracleFilterer is an auto generated log filtering Go binding around an Ethereum contract events.
type OracleFilterer struct {
contract *bind.BoundContract // Generic contract wrapper for the low level calls
}
// OracleSession is an auto generated Go binding around an Ethereum contract,
// with pre-set call and transact options.
type OracleSession struct {
Contract *Oracle // Generic contract binding to set the session for
CallOpts bind.CallOpts // Call options to use throughout this session
TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
}
// OracleCallerSession is an auto generated read-only Go binding around an Ethereum contract,
// with pre-set call options.
type OracleCallerSession struct {
Contract *OracleCaller // Generic contract caller binding to set the session for
CallOpts bind.CallOpts // Call options to use throughout this session
}
// OracleTransactorSession is an auto generated write-only Go binding around an Ethereum contract,
// with pre-set transact options.
type OracleTransactorSession struct {
Contract *OracleTransactor // Generic contract transactor binding to set the session for
TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
}
// OracleRaw is an auto generated low-level Go binding around an Ethereum contract.
type OracleRaw struct {
Contract *Oracle // Generic contract binding to access the raw methods on
}
// OracleCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.
type OracleCallerRaw struct {
Contract *OracleCaller // Generic read-only contract binding to access the raw methods on
}
// OracleTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.
type OracleTransactorRaw struct {
Contract *OracleTransactor // Generic write-only contract binding to access the raw methods on
}
// NewOracle creates a new instance of Oracle, bound to a specific deployed contract.
func NewOracle(address common.Address, backend bind.ContractBackend) (*Oracle, error) {
contract, err := bindOracle(address, backend, backend, backend)
if err != nil {
return nil, err
}
return &Oracle{OracleCaller: OracleCaller{contract: contract}, OracleTransactor: OracleTransactor{contract: contract}, OracleFilterer: OracleFilterer{contract: contract}}, nil
}
// NewOracleCaller creates a new read-only instance of Oracle, bound to a specific deployed contract.
func NewOracleCaller(address common.Address, caller bind.ContractCaller) (*OracleCaller, error) {
contract, err := bindOracle(address, caller, nil, nil)
if err != nil {
return nil, err
}
return &OracleCaller{contract: contract}, nil
}
// NewOracleTransactor creates a new write-only instance of Oracle, bound to a specific deployed contract.
func NewOracleTransactor(address common.Address, transactor bind.ContractTransactor) (*OracleTransactor, error) {
contract, err := bindOracle(address, nil, transactor, nil)
if err != nil {
return nil, err
}
return &OracleTransactor{contract: contract}, nil
}
// NewOracleFilterer creates a new log filterer instance of Oracle, bound to a specific deployed contract.
func NewOracleFilterer(address common.Address, filterer bind.ContractFilterer) (*OracleFilterer, error) {
contract, err := bindOracle(address, nil, nil, filterer)
if err != nil {
return nil, err
}
return &OracleFilterer{contract: contract}, nil
}
// bindOracle binds a generic wrapper to an already deployed contract.
func bindOracle(address common.Address, caller bind.ContractCaller, transactor bind.ContractTransactor, filterer bind.ContractFilterer) (*bind.BoundContract, error) {
parsed, err := abi.JSON(strings.NewReader(OracleABI))
if err != nil {
return nil, err
}
return bind.NewBoundContract(address, parsed, caller, transactor, filterer), nil
}
// Call invokes the (constant) contract method with params as input values and
// sets the output to result. The result type might be a single field for simple
// returns, a slice of interfaces for anonymous returns and a struct for named
// returns.
func (_Oracle *OracleRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error {
return _Oracle.Contract.OracleCaller.contract.Call(opts, result, method, params...)
}
// Transfer initiates a plain transaction to move funds to the contract, calling
// its default method if one is available.
func (_Oracle *OracleRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
return _Oracle.Contract.OracleTransactor.contract.Transfer(opts)
}
// Transact invokes the (paid) contract method with params as input values.
func (_Oracle *OracleRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
return _Oracle.Contract.OracleTransactor.contract.Transact(opts, method, params...)
}
// Call invokes the (constant) contract method with params as input values and
// sets the output to result. The result type might be a single field for simple
// returns, a slice of interfaces for anonymous returns and a struct for named
// returns.
func (_Oracle *OracleCallerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error {
return _Oracle.Contract.contract.Call(opts, result, method, params...)
}
// Transfer initiates a plain transaction to move funds to the contract, calling
// its default method if one is available.
func (_Oracle *OracleTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error) {
return _Oracle.Contract.contract.Transfer(opts)
}
// Transact invokes the (paid) contract method with params as input values.
func (_Oracle *OracleTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error) {
return _Oracle.Contract.contract.Transact(opts, method, params...)
}
// GetDerivedPrice is a free data retrieval call binding the contract method 0xb15b31de.
//
// Solidity: function getDerivedPrice(string baseAggr, string quoteAggr) view returns(int256)
func (_Oracle *OracleCaller) GetDerivedPrice(opts *bind.CallOpts, baseAggr string, quoteAggr string) (*big.Int, error) {
var out []interface{}
err := _Oracle.contract.Call(opts, &out, "getDerivedPrice", baseAggr, quoteAggr)
if err != nil {
return *new(*big.Int), err
}
out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int)
return out0, err
}
// GetDerivedPrice is a free data retrieval call binding the contract method 0xb15b31de.
//
// Solidity: function getDerivedPrice(string baseAggr, string quoteAggr) view returns(int256)
func (_Oracle *OracleSession) GetDerivedPrice(baseAggr string, quoteAggr string) (*big.Int, error) {
return _Oracle.Contract.GetDerivedPrice(&_Oracle.CallOpts, baseAggr, quoteAggr)
}
// GetDerivedPrice is a free data retrieval call binding the contract method 0xb15b31de.
//
// Solidity: function getDerivedPrice(string baseAggr, string quoteAggr) view returns(int256)
func (_Oracle *OracleCallerSession) GetDerivedPrice(baseAggr string, quoteAggr string) (*big.Int, error) {
return _Oracle.Contract.GetDerivedPrice(&_Oracle.CallOpts, baseAggr, quoteAggr)
}
// GetLatestPrice is a free data retrieval call binding the contract method 0xf66a1b71.
//
// Solidity: function getLatestPrice(string aggregator) view returns(int256, uint8)
func (_Oracle *OracleCaller) GetLatestPrice(opts *bind.CallOpts, aggregator string) (*big.Int, uint8, error) {
var out []interface{}
err := _Oracle.contract.Call(opts, &out, "getLatestPrice", aggregator)
if err != nil {
return *new(*big.Int), *new(uint8), err
}
out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int)
out1 := *abi.ConvertType(out[1], new(uint8)).(*uint8)
return out0, out1, err
}
// GetLatestPrice is a free data retrieval call binding the contract method 0xf66a1b71.
//
// Solidity: function getLatestPrice(string aggregator) view returns(int256, uint8)
func (_Oracle *OracleSession) GetLatestPrice(aggregator string) (*big.Int, uint8, error) {
return _Oracle.Contract.GetLatestPrice(&_Oracle.CallOpts, aggregator)
}
// GetLatestPrice is a free data retrieval call binding the contract method 0xf66a1b71.
//
// Solidity: function getLatestPrice(string aggregator) view returns(int256, uint8)
func (_Oracle *OracleCallerSession) GetLatestPrice(aggregator string) (*big.Int, uint8, error) {
return _Oracle.Contract.GetLatestPrice(&_Oracle.CallOpts, aggregator)
}
......@@ -22,11 +22,11 @@ import (
"offshift/secp256k1/ecc_math"
)
const StrAddrContr string = "0x5E42e4Abd32Ae39CD2094758342Da3a3e25c603d" // TO DO GLOBAL
const StrAddrContr string = "0x329c92F0BC1B6C9977C3ee462Cb7B15B787570d0" // preview ver. "0x5E42e4Abd32Ae39CD2094758342Da3a3e25c603d"
var ProjInfura string = "https://goerli.infura.io/v3/179491410de5450cb20f88593067a22c" // TO DO GLOBAL
var PathToFile string = "./parser/store.json"
var logFillTransfered = common.HexToHash("a51f9f65398a9972aa4f5ddc88ee2b973e5ef049ef37a1f30f24c15e69a73482")
var logFillCommitmentTransferred = common.HexToHash("a51f9f65398a9972aa4f5ddc88ee2b973e5ef049ef37a1f30f24c15e69a73482")
type eventCommitmentTransferredType struct {
SenderCommitmentId *big.Int
......@@ -37,6 +37,14 @@ type eventCommitmentTransferredType struct {
RecipientInd common.Address // indexed
}
var logFillExcessed = common.HexToHash("4961f467667aa361a898d8db6efefeaac6778c684fca1b9ed126ba277e758666")
type eventExcessedType struct {
Commitment ecc_math.ECPoint
SenderInd common.Address // indexed
CommitmentIdInd *big.Int // indexed
}
var logFillDeposited = common.HexToHash("41d4bfd2bee36f917401f51645c0cbe7954976e1f3ee2a04e3b77bc53e6d5eda")
type eventDepositedType struct {
......@@ -55,7 +63,7 @@ type eventWithdrawnType struct {
CommitmentIdOldInd *big.Int // indexed
}
var logFillGrouped = common.HexToHash("0xe07238879edf47d3ca900ecd5ecbb009379ca247858539dc596edacc9e2ff3d7")
var logFillGrouped = common.HexToHash("0xecba3ed80d36f2c623357de5ca1d4993d3a2c78f71dda76e194a923dc6222f39")
type eventGroupedType struct {
Commitment ecc_math.ECPoint `json:"commitment"`
......@@ -74,7 +82,8 @@ type dataStore struct {
Amount *big.Int `json:"amount"`
PrivateKey *big.Int `json:"privateKey"`
PublicKey ecc_math.ECPoint `json:"publicKey"`
Status string `json:"status"`
//ValR *big.Int `json:"r"` // TO DO !!!!!
Status string `json:"status"`
}
type StoreDatas struct {
......@@ -103,11 +112,18 @@ func (StoreDatas *StoreDatas) AddStore(store *dataStore) {
StoreDatas.Store = append(StoreDatas.Store[:], store)
}
func (StoreDatas *StoreDatas) PosTxInStore(txHash common.Hash) int64 {
func (StoreDatas *StoreDatas) PosTxInStore(txHash common.Hash, txType string) int64 {
//seek and return number position tx in Store data set, if not find then return -1
for i, vSt := range StoreDatas.Store {
if txHash == common.HexToHash(vSt.TxHashInp) || txHash == common.HexToHash(vSt.TxHashOutp) {
return int64(i)
switch txType {
case "input":
if txHash == common.HexToHash(vSt.TxHashInp) {
return int64(i)
}
case "output":
if txHash == common.HexToHash(vSt.TxHashOutp) {
return int64(i)
}
}
}
return -1
......@@ -119,10 +135,15 @@ func (vSt *dataStore) IsDataParsed() bool {
return isGood
}
func (vSt *dataStore) VerifyCommitment() bool {
func (vSt *dataStore) VerifyCommitment(needPars bool) bool {
verifyParsed := true
// is commitment parsed
verifyParsed := vSt.IsDataParsed()
fmt.Println("verifyParsed", verifyParsed)
if needPars {
verifyParsed := vSt.IsDataParsed()
fmt.Println("verifyParsed", verifyParsed)
} else {
fmt.Println("Not verify is parsed")
}
//amount need > 0
verifyAmount := vSt.Amount.Cmp(big.NewInt(0)) == 1
......@@ -172,13 +193,13 @@ func (StoreDatas *StoreDatas) GetDataSetByCommitment(comm ecc_math.ECPoint) (*da
//function verify private key, public key, amount, commitment
func (StoreDatas *StoreDatas) VerifyCommitmentByPos(posComm int) bool {
return StoreDatas.Store[posComm].VerifyCommitment()
return StoreDatas.Store[posComm].VerifyCommitment(true)
}
func (StoreDatas *StoreDatas) GetBalanceCommitments() (*big.Int, error) {
balance := big.NewInt(0)
for _, vSt := range StoreDatas.Store {
if vSt.VerifyCommitment() {
if vSt.VerifyCommitment(true) {
balance = new(big.Int).Add(vSt.Amount, balance)
} else {
fmt.Println("id", vSt.CommitmentId, "bad data", vSt.Commitment)
......@@ -227,17 +248,17 @@ func ParsLog(abi abi.ABI, logs []types.Log, data *StoreDatas) (*StoreDatas, erro
var eventWithdrawn eventWithdrawnType
var eventCommitmentTransferred eventCommitmentTransferredType
var eventGrouped eventGroupedType
var eventExcessed eventExcessedType
var posComm, posTx int64
ownerAccount := common.HexToAddress(data.Parsing.OwnerAccount.Hex())
for i, vLog := range logs {
senderTx := common.HexToAddress(vLog.Topics[1].Hex())
fmt.Println(i)
fmt.Println("\n", i)
if data.Parsing.ViewBlock < vLog.BlockNumber {
data.Parsing.ViewBlock = vLog.BlockNumber
}
//dataStore0 := dataStore{"", "", big.NewInt(0), ecc_math.ECPoint{X: big.NewInt(0), Y: big.NewInt(0)}, big.NewInt(0), big.NewInt(0), ecc_math.ECPoint{X: big.NewInt(0), Y: big.NewInt(0)}, ""}
dataStore0 := new(StoreDatas).NewStore()
if vLog.Topics[0] == logFillDeposited {
......@@ -251,7 +272,7 @@ func ParsLog(abi abi.ABI, logs []types.Log, data *StoreDatas) (*StoreDatas, erro
fmt.Println("\nERROR UnpackIntoInterface eventDeposited:\n", err.Error())
return data, err
}
posTx = data.PosTxInStore(vLog.TxHash)
posTx = data.PosTxInStore(vLog.TxHash, "input")
if posTx == -1 {
// add new element in to data.Store
dataStore0.TxHashInp = vLog.TxHash.String()
......@@ -268,7 +289,7 @@ func ParsLog(abi abi.ABI, logs []types.Log, data *StoreDatas) (*StoreDatas, erro
}
}
} else {
fmt.Println("in tx:", vLog.TxHash, "sender "+ownerAccount.String()+" is not you")
fmt.Println(vLog.TxHash, ": sender tx ", senderTx, " is not you", ownerAccount)
}
}
if vLog.Topics[0] == logFillWithdrawn {
......@@ -286,7 +307,7 @@ func ParsLog(abi abi.ABI, logs []types.Log, data *StoreDatas) (*StoreDatas, erro
eventWithdrawn.CommitmentIdOldInd = vLog.Topics[2].Big()
// seek record in data data (id, comm) == log (id, comm)
posComm = data.PosCommitmentInStore(eventWithdrawn.CommitmentIdOldInd, eventWithdrawn.CommitmentOld)
posTx = data.PosTxInStore(vLog.TxHash)
posTx = data.PosTxInStore(vLog.TxHash, "output")
if posTx == -1 {
if posComm != -1 {
fmt.Println("withdraw posComm is find")
......@@ -307,103 +328,136 @@ func ParsLog(abi abi.ABI, logs []types.Log, data *StoreDatas) (*StoreDatas, erro
data.Store[posComm].Status = "spent"
}
} else {
fmt.Println("in tx:", vLog.TxHash, "sender "+ownerAccount.String()+" is not you")
fmt.Println(vLog.TxHash, ": sender tx ", senderTx, " is not you", ownerAccount)
}
}
if vLog.Topics[0] == logFillTransfered {
if vLog.Topics[0] == logFillCommitmentTransferred {
fmt.Println(vLog.TxHash, ": Transfered")
err := abi.UnpackIntoInterface(&eventCommitmentTransferred, "CommitmentTransferred", vLog.Data)
if err != nil {
fmt.Println("/nERROR UnpackIntoInterface eventCommitmentTransferred:/n", err.Error())
}
posTx = data.PosTxInStore(vLog.TxHash)
recipientTx := common.HexToAddress(vLog.Topics[2].Hex())
if senderTx == ownerAccount {
// input data before pars. transfer for sender: txInp, txOutp, amount, commitmSender, privKeySender, publKeySender
// output data after pars. transfer for sender: commId, status: commIdSender "spent"
posComm = data.PosCommitmentInStore(eventCommitmentTransferred.SenderCommitmentId, eventCommitmentTransferred.SenderCommitment)
if posTx == -1 {
if posComm != -1 {
// posTx == -1 posComm == -1
data.Store[posComm].TxHashOutp = vLog.TxHash.String()
data.Store[posComm].Status = "spent"
fmt.Println("\nERROR UnpackIntoInterface eventCommitmentTransferred:\n", err.Error())
} else {
posTx = data.PosTxInStore(vLog.TxHash, "input")
recipientTx := common.HexToAddress(vLog.Topics[2].Hex())
if senderTx == ownerAccount {
// input data before pars. transfer for sender: txInp, txOutp, amount, commitmSender, privKeySender, publKeySender
// output data after pars. transfer for sender: commId, status: commIdSender "spent"
posComm = data.PosCommitmentInStore(eventCommitmentTransferred.SenderCommitmentId, eventCommitmentTransferred.SenderCommitment)
if posTx == -1 {
if posComm != -1 {
// posTx == -1 posComm == -1
data.Store[posComm].TxHashOutp = vLog.TxHash.String()
data.Store[posComm].Status = "spent"
} else {
// posTx == -1 posComm == -1
// add new element in to data.Store
dataStore0.TxHashOutp = vLog.TxHash.String()
dataStore0.CommitmentId = eventCommitmentTransferred.SenderCommitmentId
dataStore0.Commitment = eventCommitmentTransferred.SenderCommitment
dataStore0.Status = "spent"
data.Store = append(data.Store[:], dataStore0)
}
} else {
// posTx == -1 posComm == -1
// posTx != -1
data.Store[posTx].Status = "spent"
}
}
if recipientTx == ownerAccount {
// input data before pars. transfer for recipient: amount, commitmRec, privKeyRec, publKeyRec
// output data after pars. transfer for sender:txInp, commIdRec, status: "unspent"
//find data store with recipient commitment & verify commitment
_, posComm, err := data.GetDataSetByCommitment(eventCommitmentTransferred.RecipientCommitment)
if err != nil {
// add new element in to data.Store
dataStore0.TxHashOutp = vLog.TxHash.String()
dataStore0.CommitmentId = eventCommitmentTransferred.SenderCommitmentId
dataStore0.Commitment = eventCommitmentTransferred.SenderCommitment
dataStore0.Status = "spent"
dataStore0.TxHashInp = vLog.TxHash.String()
dataStore0.CommitmentId = eventCommitmentTransferred.RecipientCommitmentId
dataStore0.Commitment = eventCommitmentTransferred.RecipientCommitment
dataStore0.Status = "unspent"
data.Store = append(data.Store[:], dataStore0)
fmt.Println("recipient commitment is no find")
} else if data.Store[posComm].TxHashInp != "" && data.Store[posComm].Status != "" {
fmt.Println("store for recipient commitment is filled")
} else if data.Store[posComm].VerifyCommitment(false) {
data.Store[posComm].TxHashInp = vLog.TxHash.String()
data.Store[posComm].CommitmentId = eventCommitmentTransferred.RecipientCommitmentId
data.Store[posComm].Status = "unspent"
} else {
fmt.Println("recipient commitment is no correct, data set not updated")
}
} else {
// posTx != -1
data.Store[posTx].Status = "spent"
}
}
if recipientTx == ownerAccount {
// input data before pars. transfer for recipient: txInp, amount, commitmRec, privKeyRec, publKeyRec
// output data after pars. transfer for sender: commIdRec, status: "unspent"
posComm = data.PosCommitmentInStore(eventCommitmentTransferred.RecipientCommitmentId, eventCommitmentTransferred.RecipientCommitment)
if posTx == -1 {
// add new element in to data.Store
dataStore0.TxHashInp = vLog.TxHash.String()
dataStore0.CommitmentId = eventCommitmentTransferred.RecipientCommitmentId
dataStore0.Commitment = eventCommitmentTransferred.RecipientCommitment
dataStore0.Status = "unspent"
data.Store = append(data.Store[:], dataStore0)
} else {
data.Store[posTx].CommitmentId = eventCommitmentTransferred.RecipientCommitmentId
data.Store[posTx].Status = "unspent"
if senderTx != ownerAccount && recipientTx != ownerAccount {
fmt.Println(vLog.TxHash, "in tx:", "sender", senderTx, "or recipient ", recipientTx, " is not you", ownerAccount)
}
}
if senderTx != ownerAccount && recipientTx != ownerAccount {
fmt.Println("in tx:", vLog.TxHash, "sender or recipient "+ownerAccount.String()+" is not you")
}
}
if vLog.Topics[0] == logFillGrouped {
//input data before pars. group: txInp, txOutput, amount, commitment, priv.key, pub.key, unspent
//output data after pars. group: status: "unspent"
fmt.Println(vLog.TxHash, ": Grouped")
if senderTx == ownerAccount { //!!!!!!
//if true { // delete
if senderTx == ownerAccount {
err := abi.UnpackIntoInterface(&eventGrouped, "Grouped", vLog.Data)
if err != nil {
fmt.Println("\nERROR UnpackIntoInterface eventGrouped:\n", err.Error())
return data, err
}
if data.PosTxInStore(vLog.TxHash) == -1 {
if data.PosTxInStore(vLog.TxHash, "output") == -1 {
// add new element in to data.Store
dataStore0.TxHashInp = vLog.TxHash.String()
dataStore0.CommitmentId = vLog.Topics[1].Big() // delete
//dataStore0.CommitmentId = vLog.Topics[2].Big() // !!!!!!!
dataStore0.CommitmentId = vLog.Topics[2].Big()
dataStore0.Commitment = eventGrouped.Commitment
dataStore0.Status = "unspent"
data.Store = append(data.Store[:], dataStore0)
} else {
for pos, vSt := range data.Store {
switch vLog.TxHash.String() {
case vSt.TxHashInp:
data.Store[pos].CommitmentId = vLog.Topics[1].Big() // delete
//data.Store[pos].CommitmentId = vLog.Topics[2].Big() // !!!!!!!
if vSt.TxHashInp == vLog.TxHash.String() {
data.Store[pos].CommitmentId = vLog.Topics[2].Big()
data.Store[pos].Status = "unspent"
case vSt.TxHashOutp:
}
if vSt.TxHashOutp == vLog.TxHash.String() {
data.Store[pos].Status = "spent"
}
}
if data.Store[posTx].Status == "" {
// tx is new and not filled
data.Store[posTx].CommitmentId = vLog.Topics[1].Big()
//data.Store[posTx].CommitmentId = vLog.Topics[2].Big() // !!!!
data.Store[posTx].CommitmentId = vLog.Topics[2].Big()
data.Store[posTx].Status = "unspent"
}
}
} else {
//fmt.Println("in tx:", vLog.TxHash, "sender "+ownerAccount.String()+" is not you")
fmt.Println(vLog.TxHash, ": sender tx ", senderTx, " is not you", ownerAccount)
}
}
if vLog.Topics[0] == logFillExcessed {
fmt.Println(vLog.TxHash, ": Excessed")
if senderTx == ownerAccount {
err := abi.UnpackIntoInterface(&eventExcessed, "Excessed", vLog.Data)
if err != nil {
fmt.Println("\nERROR UnpackIntoInterface eventExcessed:\n", err.Error())
} else {
posTx = data.PosTxInStore(vLog.TxHash, "inp")
if posTx == -1 {
_, posComm, err := data.GetDataSetByCommitment(eventExcessed.Commitment)
if err != nil {
fmt.Println("eventExcessed: ", err.Error())
} else {
data.Store[posComm].TxHashInp = vLog.TxHash.String()
data.Store[posComm].CommitmentId = vLog.Topics[2].Big()
data.Store[posComm].Status = "unspent"
}
} else {
if data.Store[posTx].Status != "spent" {
data.Store[posTx].CommitmentId = vLog.Topics[2].Big()
data.Store[posTx].Status = "unspent"
}
}
}
} else {
fmt.Println(vLog.TxHash, ": sender tx ", senderTx, " is not you", ownerAccount)
}
}
}
return data, nil
}
......
{"parsing":{"ownerAccount":"0x7d9a5088f4096ea11b46afec92dffe225bfa5c57","viewBlock":6501436},"store":[{"txHashInp":"0x512d976e64b1b28c1c86730402d1d90343be48afd03d2df81c2c8298b492f95c","txHashOutp":"","commitmentId":1,"commitment":{"X":66094604039781064722234945043050410683289704824087184254838036935844033193102,"Y":106000274024451189398421454570631843793296446984871242295519990741976274687243},"amount":300000000000000000,"privateKey":107418959676773555301258270395857841770511125976755548767582081681518831673172,"publicKey":{"X":87453105025861587196942817582455323884789576479152430738482192598085203595820,"Y":35113133067460940097400289266577159971002755890931457187514995113300964382519},"status":"unspent"}]}
{"parsing":{"ownerAccount":"0xf58fab89afac097ae8db81a67a01aaf456a361a5","viewBlock":6427123},"store":[{"txHashInp":"0x16b5c5e9c874c683fe81577f0f37ea748dc620e205da5dc5489034d4a208cebc","txHashOutp":"","commitmentId":1,"commitment":{"X":37213474322201772456965805664128617556256893904284878111262013317798539501986,"Y":66991299650143557679905862228446192980027335597299425010414447648898102004653},"amount":5000000000000000000,"privateKey":92565078248595308973379325310896926685674296651197853539801750559642184266831,"publicKey":{"X":115611249988509878358734053180814432461961881016415574138803544504742025214115,"Y":2584219621269395991517938851170168035985090435007435487134557264687359435214},"status":"unspent"},{"txHashInp":"0x419e25aaf1fc98d76d99f01258cf7189d73a4c587261f0ae09e555c3746c0dda"