github.com/Night-mk/quorum@v21.1.0+incompatible/private/engine/constellation/constellation.go (about) 1 package constellation 2 3 import ( 4 "fmt" 5 6 "github.com/ethereum/go-ethereum/private/engine" 7 8 "github.com/ethereum/go-ethereum/common" 9 "github.com/ethereum/go-ethereum/private/cache" 10 11 gocache "github.com/patrickmn/go-cache" 12 ) 13 14 type constellation struct { 15 node *Client 16 c *gocache.Cache 17 } 18 19 func Is(ptm interface{}) bool { 20 _, ok := ptm.(*constellation) 21 return ok 22 } 23 24 func New(client *engine.Client) *constellation { 25 return &constellation{ 26 node: &Client{ 27 httpClient: client.HttpClient, 28 }, 29 c: gocache.New(cache.DefaultExpiration, cache.CleanupInterval), 30 } 31 } 32 33 func (g *constellation) Send(data []byte, from string, to []string, extra *engine.ExtraMetadata) (string, []string, common.EncryptedPayloadHash, error) { 34 if extra.PrivacyFlag.IsNotStandardPrivate() { 35 return "", nil, common.EncryptedPayloadHash{}, engine.ErrPrivateTxManagerDoesNotSupportPrivacyEnhancements 36 } 37 out, err := g.node.SendPayload(data, from, to, extra.ACHashes, extra.ACMerkleRoot) 38 if err != nil { 39 return "", nil, common.EncryptedPayloadHash{}, err 40 } 41 cacheKey := string(out.Bytes()) 42 g.c.Set(cacheKey, cache.PrivateCacheItem{ 43 Payload: data, 44 Extra: *extra, 45 }, cache.DefaultExpiration) 46 return "", nil, out, nil 47 } 48 49 func (g *constellation) EncryptPayload(data []byte, from string, to []string, extra *engine.ExtraMetadata) ([]byte, error) { 50 return nil, engine.ErrPrivateTxManagerNotSupported 51 } 52 53 func (g *constellation) DecryptPayload(payload common.DecryptRequest) ([]byte, *engine.ExtraMetadata, error) { 54 return nil, nil, engine.ErrPrivateTxManagerNotSupported 55 } 56 57 func (g *constellation) StoreRaw(data []byte, from string) (common.EncryptedPayloadHash, error) { 58 return common.EncryptedPayloadHash{}, engine.ErrPrivateTxManagerNotSupported 59 } 60 61 func (g *constellation) SendSignedTx(data common.EncryptedPayloadHash, to []string, extra *engine.ExtraMetadata) (string, []string, []byte, error) { 62 return "", nil, nil, engine.ErrPrivateTxManagerNotSupported 63 } 64 65 func (g *constellation) ReceiveRaw(data common.EncryptedPayloadHash) ([]byte, string, *engine.ExtraMetadata, error) { 66 return nil, "", nil, engine.ErrPrivateTxManagerNotSupported 67 } 68 69 func (g *constellation) IsSender(txHash common.EncryptedPayloadHash) (bool, error) { 70 return false, engine.ErrPrivateTxManagerNotSupported 71 } 72 73 func (g *constellation) GetParticipants(txHash common.EncryptedPayloadHash) ([]string, error) { 74 return nil, engine.ErrPrivateTxManagerNotSupported 75 } 76 77 func (g *constellation) Receive(data common.EncryptedPayloadHash) (string, []string, []byte, *engine.ExtraMetadata, error) { 78 if common.EmptyEncryptedPayloadHash(data) { 79 return "", nil, nil, nil, nil 80 } 81 // Ignore this error since not being a recipient of 82 // a payload isn't an error. 83 // TODO: Return an error if it's anything OTHER than 84 // 'you are not a recipient.' 85 cacheKey := string(data.Bytes()) 86 x, found := g.c.Get(cacheKey) 87 if found { 88 cacheItem, ok := x.(cache.PrivateCacheItem) 89 if !ok { 90 return "", nil, nil, nil, fmt.Errorf("unknown cache item. expected type PrivateCacheItem") 91 } 92 return "", nil, cacheItem.Payload, &cacheItem.Extra, nil 93 } 94 privatePayload, acHashes, acMerkleRoot, err := g.node.ReceivePayload(data) 95 if nil != err { 96 return "", nil, nil, nil, err 97 } 98 extra := engine.ExtraMetadata{ 99 ACHashes: acHashes, 100 ACMerkleRoot: acMerkleRoot, 101 } 102 g.c.Set(cacheKey, cache.PrivateCacheItem{ 103 Payload: privatePayload, 104 Extra: extra, 105 }, cache.DefaultExpiration) 106 return "", nil, privatePayload, &extra, nil 107 } 108 109 func (g *constellation) Name() string { 110 return "Constellation" 111 } 112 113 func (g *constellation) HasFeature(f engine.PrivateTransactionManagerFeature) bool { 114 return false 115 }