5
5
"fmt"
6
6
"math"
7
7
"math/big"
8
- "strings"
9
8
10
9
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
11
10
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -25,10 +24,6 @@ var ERC20TransferTopic = common.HexToHash("0xddf252ad1be2c89b69c2b068fc378daa952
25
24
var ERC721TransferTopic = common .HexToHash ("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" )
26
25
var ERC721ApprovalTopic = common .HexToHash ("0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925" )
27
26
var ERC721ApproveAllTopic = common .HexToHash ("0x17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31" )
28
- var ERC1155TransferSingleTopic = common .HexToHash ("0xc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f62" )
29
- var ERC1155TransferBatchTopic = common .HexToHash ("0x4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb" )
30
- var ERC1155ApprovalForAllTopic = common .HexToHash ("0x17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31" )
31
- var ERC1155URITopic = common .HexToHash ("0x6bb7ff708619ba0610cba295a58592e0451dee2622938c8755667688daf3529b" )
32
27
var EmptyHash = common .HexToHash ("0x0" )
33
28
var TrueHash = common .HexToHash ("0x1" )
34
29
@@ -96,16 +91,6 @@ func (app *App) AddCosmosEventsToEVMReceiptIfApplicable(ctx sdk.Context, tx sdk.
96
91
}
97
92
continue
98
93
}
99
- // check if there is a ERC1155 pointer to contract Addr
100
- pointerAddr , _ , exists = app .EvmKeeper .GetERC1155CW1155Pointer (ctx , contractAddr )
101
- if exists {
102
- log , eligible := app .translateCW1155Event (ctx , wasmEvent , pointerAddr , contractAddr )
103
- if eligible {
104
- log .Index = uint (len (logs ))
105
- logs = append (logs , log )
106
- }
107
- continue
108
- }
109
94
}
110
95
if len (logs ) == 0 {
111
96
return
@@ -334,99 +319,6 @@ func (app *App) translateCW721Event(ctx sdk.Context, wasmEvent abci.Event, point
334
319
return nil , false
335
320
}
336
321
337
- func (app * App ) translateCW1155Event (ctx sdk.Context , wasmEvent abci.Event , pointerAddr common.Address , contractAddr string ) (* ethtypes.Log , bool ) {
338
- action , found := GetAttributeValue (wasmEvent , "action" )
339
- if ! found {
340
- return nil , false
341
- }
342
- var topics []common.Hash
343
- switch action {
344
- case "transfer_single" , "mint_single" , "burn_single" :
345
- fromHash := EmptyHash
346
- toHash := EmptyHash
347
- if action != "mint_single" {
348
- fromHash = app .GetEvmAddressAttribute (ctx , wasmEvent , "owner" )
349
- }
350
- if action != "burn_single" {
351
- toHash = app .GetEvmAddressAttribute (ctx , wasmEvent , "recipient" )
352
- }
353
- topics = []common.Hash {
354
- ERC1155TransferSingleTopic ,
355
- app .GetEvmAddressAttribute (ctx , wasmEvent , "sender" ),
356
- fromHash ,
357
- toHash ,
358
- }
359
- tokenID := GetTokenIDAttribute (wasmEvent )
360
- if tokenID == nil {
361
- return nil , false
362
- }
363
- tokenAmount , found := GetAmountAttribute (wasmEvent )
364
- if ! found {
365
- return nil , false
366
- }
367
- dataHash1 := common .BigToHash (tokenID ).Bytes ()
368
- dataHash2 := common .BigToHash (tokenAmount ).Bytes ()
369
- return & ethtypes.Log {
370
- Address : pointerAddr ,
371
- Topics : topics ,
372
- Data : append (dataHash1 , dataHash2 ... ),
373
- }, true
374
- case "transfer_batch" , "mint_batch" , "burn_batch" :
375
- fromHash := EmptyHash
376
- toHash := EmptyHash
377
- if action != "mint_batch" {
378
- fromHash = app .GetEvmAddressAttribute (ctx , wasmEvent , "owner" )
379
- }
380
- if action != "burn_batch" {
381
- toHash = app .GetEvmAddressAttribute (ctx , wasmEvent , "recipient" )
382
- }
383
- topics = []common.Hash {
384
- ERC1155TransferBatchTopic ,
385
- app .GetEvmAddressAttribute (ctx , wasmEvent , "sender" ),
386
- fromHash ,
387
- toHash ,
388
- }
389
- tokenIDs , found := GetTokenIDsAttribute (wasmEvent )
390
- if ! found {
391
- return nil , false
392
- }
393
- tokenAmounts , found := GetAmountsAttribute (wasmEvent )
394
- if ! found {
395
- return nil , false
396
- }
397
- value := EncodeBigIntArray (tokenIDs )
398
- value = append (value , EncodeBigIntArray (tokenAmounts )... )
399
- return & ethtypes.Log {
400
- Address : pointerAddr ,
401
- Topics : topics ,
402
- Data : value ,
403
- }, true
404
- case "approve_all" :
405
- topics = []common.Hash {
406
- ERC1155ApprovalForAllTopic ,
407
- app .GetEvmAddressAttribute (ctx , wasmEvent , "sender" ),
408
- app .GetEvmAddressAttribute (ctx , wasmEvent , "operator" ),
409
- }
410
- return & ethtypes.Log {
411
- Address : pointerAddr ,
412
- Topics : topics ,
413
- Data : TrueHash .Bytes (),
414
- }, true
415
- case "revoke_all" :
416
- topics = []common.Hash {
417
- ERC1155ApprovalForAllTopic ,
418
- app .GetEvmAddressAttribute (ctx , wasmEvent , "sender" ),
419
- app .GetEvmAddressAttribute (ctx , wasmEvent , "operator" ),
420
- }
421
- return & ethtypes.Log {
422
- Address : pointerAddr ,
423
- Topics : topics ,
424
- Data : EmptyHash .Bytes (),
425
- }, true
426
- }
427
- return nil , false
428
- }
429
-
430
322
func (app * App ) GetEvmAddressAttribute (ctx sdk.Context , event abci.Event , attribute string ) common.Hash {
431
323
addrStr , found := GetAttributeValue (event , attribute )
432
324
if found {
@@ -468,22 +360,6 @@ func GetAmountAttribute(event abci.Event) (*big.Int, bool) {
468
360
return nil , false
469
361
}
470
362
471
- func GetAmountsAttribute (event abci.Event ) ([]* big.Int , bool ) {
472
- results := []* big.Int {}
473
- amounts , found := GetAttributeValue (event , "amounts" )
474
- if ! found {
475
- return results , false
476
- }
477
- for _ , amt := range strings .Split (amounts , "," ) {
478
- amtInt , ok := sdk .NewIntFromString (amt )
479
- if ! ok {
480
- return results , false
481
- }
482
- results = append (results , amtInt .BigInt ())
483
- }
484
- return results , true
485
- }
486
-
487
363
func GetTokenIDAttribute (event abci.Event ) * big.Int {
488
364
tokenID , found := GetAttributeValue (event , "token_id" )
489
365
if ! found {
@@ -495,36 +371,3 @@ func GetTokenIDAttribute(event abci.Event) *big.Int {
495
371
}
496
372
return tokenIDInt .BigInt ()
497
373
}
498
-
499
- func GetTokenIDsAttribute (event abci.Event ) ([]* big.Int , bool ) {
500
- results := []* big.Int {}
501
- tokenIDs , found := GetAttributeValue (event , "token_ids" )
502
- if ! found {
503
- return results , false
504
- }
505
- for _ , tid := range strings .Split (tokenIDs , "," ) {
506
- tidInt , ok := sdk .NewIntFromString (tid )
507
- if ! ok {
508
- return results , false
509
- }
510
- results = append (results , tidInt .BigInt ())
511
- }
512
- return results , true
513
- }
514
-
515
- func EncodeBigIntArray (inputs []* big.Int ) []byte {
516
- // Arrays are broken up into components:
517
- // - offset byte (always 32)
518
- // - length of array
519
- // - ...array values
520
- offset := big .NewInt (32 )
521
- length := big .NewInt (int64 (len (inputs )))
522
- value := append (
523
- common .BigToHash (offset ).Bytes (),
524
- common .BigToHash (length ).Bytes ()... ,
525
- )
526
- for _ , i := range inputs {
527
- value = append (value , common .BigToHash (i ).Bytes ()... )
528
- }
529
- return value
530
- }
0 commit comments