Generalize erc20transfers to tokentransfers in api
parent
81e105dd4f
commit
7da714bec4
12
api/types.go
12
api/types.go
|
@ -115,15 +115,16 @@ type Erc20Token struct {
|
||||||
ContractIndex string `json:"-"`
|
ContractIndex string `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Erc20Transfer contains info about ERC20 transfer done in a transaction
|
// TokenTransfer contains info about a token transfer done in a transaction
|
||||||
type Erc20Transfer struct {
|
type TokenTransfer struct {
|
||||||
|
Type string `json:"type"`
|
||||||
From string `json:"from"`
|
From string `json:"from"`
|
||||||
To string `json:"to"`
|
To string `json:"to"`
|
||||||
Contract string `json:"contract"`
|
Token string `json:"token"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Symbol string `json:"symbol"`
|
Symbol string `json:"symbol"`
|
||||||
Decimals int `json:"decimals"`
|
Decimals int `json:"decimals"`
|
||||||
Tokens *Amount `json:"tokens"`
|
Value *Amount `json:"value"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// EthereumSpecific contains ethereum specific transaction data
|
// EthereumSpecific contains ethereum specific transaction data
|
||||||
|
@ -154,7 +155,7 @@ type Tx struct {
|
||||||
Hex string `json:"hex,omitempty"`
|
Hex string `json:"hex,omitempty"`
|
||||||
CoinSpecificData interface{} `json:"-"`
|
CoinSpecificData interface{} `json:"-"`
|
||||||
CoinSpecificJSON json.RawMessage `json:"-"`
|
CoinSpecificJSON json.RawMessage `json:"-"`
|
||||||
Erc20Transfers []Erc20Transfer `json:"erc20transfers,omitempty"`
|
TokenTransfers []TokenTransfer `json:"tokentransfers,omitempty"`
|
||||||
EthereumSpecific *EthereumSpecific `json:"ethereumspecific,omitempty"`
|
EthereumSpecific *EthereumSpecific `json:"ethereumspecific,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,6 +175,7 @@ const (
|
||||||
AddressFilterVoutOutputs = -3
|
AddressFilterVoutOutputs = -3
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// AddressFilter is used to filter data returned from GetAddress api method
|
||||||
type AddressFilter struct {
|
type AddressFilter struct {
|
||||||
Vout int
|
Vout int
|
||||||
Contract string
|
Contract string
|
||||||
|
|
|
@ -112,7 +112,7 @@ func (w *Worker) GetTransaction(txid string, spendingTxs bool, specificJSON bool
|
||||||
func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height uint32, spendingTxs bool, specificJSON bool) (*Tx, error) {
|
func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height uint32, spendingTxs bool, specificJSON bool) (*Tx, error) {
|
||||||
var err error
|
var err error
|
||||||
var ta *db.TxAddresses
|
var ta *db.TxAddresses
|
||||||
var erc20t []Erc20Transfer
|
var tokens []TokenTransfer
|
||||||
var ethSpecific *EthereumSpecific
|
var ethSpecific *EthereumSpecific
|
||||||
var blockhash string
|
var blockhash string
|
||||||
if bchainTx.Confirmations > 0 {
|
if bchainTx.Confirmations > 0 {
|
||||||
|
@ -222,7 +222,7 @@ func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height uint32,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("GetErc20FromTx error %v, %v", err, bchainTx)
|
glog.Errorf("GetErc20FromTx error %v, %v", err, bchainTx)
|
||||||
}
|
}
|
||||||
erc20t = make([]Erc20Transfer, len(ets))
|
tokens = make([]TokenTransfer, len(ets))
|
||||||
for i := range ets {
|
for i := range ets {
|
||||||
e := &ets[i]
|
e := &ets[i]
|
||||||
cd, err := w.chainParser.GetAddrDescFromAddress(e.Contract)
|
cd, err := w.chainParser.GetAddrDescFromAddress(e.Contract)
|
||||||
|
@ -237,12 +237,13 @@ func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height uint32,
|
||||||
if erc20c == nil {
|
if erc20c == nil {
|
||||||
erc20c = &bchain.Erc20Contract{Name: e.Contract}
|
erc20c = &bchain.Erc20Contract{Name: e.Contract}
|
||||||
}
|
}
|
||||||
erc20t[i] = Erc20Transfer{
|
tokens[i] = TokenTransfer{
|
||||||
Contract: e.Contract,
|
Type: "ERC20",
|
||||||
|
Token: e.Contract,
|
||||||
From: e.From,
|
From: e.From,
|
||||||
To: e.To,
|
To: e.To,
|
||||||
Decimals: erc20c.Decimals,
|
Decimals: erc20c.Decimals,
|
||||||
Tokens: (*Amount)(&e.Tokens),
|
Value: (*Amount)(&e.Tokens),
|
||||||
Name: erc20c.Name,
|
Name: erc20c.Name,
|
||||||
Symbol: erc20c.Symbol,
|
Symbol: erc20c.Symbol,
|
||||||
}
|
}
|
||||||
|
@ -289,7 +290,7 @@ func (w *Worker) GetTransactionFromBchainTx(bchainTx *bchain.Tx, height uint32,
|
||||||
Vout: vouts,
|
Vout: vouts,
|
||||||
CoinSpecificData: bchainTx.CoinSpecificData,
|
CoinSpecificData: bchainTx.CoinSpecificData,
|
||||||
CoinSpecificJSON: sj,
|
CoinSpecificJSON: sj,
|
||||||
Erc20Transfers: erc20t,
|
TokenTransfers: tokens,
|
||||||
EthereumSpecific: ethSpecific,
|
EthereumSpecific: ethSpecific,
|
||||||
}
|
}
|
||||||
return r, nil
|
return r, nil
|
||||||
|
|
|
@ -69,11 +69,11 @@
|
||||||
{{formatAmount $tx.ValueOutSat}} {{$cs}}
|
{{formatAmount $tx.ValueOutSat}} {{$cs}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{- if $tx.Erc20Transfers -}}
|
{{- if $tx.TokenTransfers -}}
|
||||||
<div class="row line-top" style="padding: 15px 0 6px 15px;font-weight: bold;">
|
<div class="row line-top" style="padding: 15px 0 6px 15px;font-weight: bold;">
|
||||||
ERC20 Token Transfers
|
ERC20 Token Transfers
|
||||||
</div>
|
</div>
|
||||||
{{- range $erc20 := $tx.Erc20Transfers -}}
|
{{- range $erc20 := $tx.TokenTransfers -}}
|
||||||
<div class="row" style="padding: 2px 15px;">
|
<div class="row" style="padding: 2px 15px;">
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -106,7 +106,7 @@
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-3 text-right" style="padding: .4rem 0;">{{formatAmountWithDecimals $erc20.Tokens $erc20.Decimals}} {{$erc20.Symbol}}</div>
|
<div class="col-md-3 text-right" style="padding: .4rem 0;">{{formatAmountWithDecimals $erc20.Value $erc20.Decimals}} {{$erc20.Symbol}}</div>
|
||||||
</div>
|
</div>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
<div class="row" style="padding: 6px 15px;"></div>
|
<div class="row" style="padding: 6px 15px;"></div>
|
||||||
|
|
Loading…
Reference in New Issue