github.com/MetalBlockchain/metalgo@v1.11.9/vms/avm/network/atomic.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package network 5 6 import ( 7 "context" 8 "time" 9 10 "github.com/MetalBlockchain/metalgo/ids" 11 "github.com/MetalBlockchain/metalgo/snow/engine/common" 12 "github.com/MetalBlockchain/metalgo/utils" 13 ) 14 15 var _ Atomic = (*atomic)(nil) 16 17 type Atomic interface { 18 common.AppHandler 19 20 Set(common.AppHandler) 21 } 22 23 type atomic struct { 24 handler utils.Atomic[common.AppHandler] 25 } 26 27 func NewAtomic(h common.AppHandler) Atomic { 28 a := &atomic{} 29 a.handler.Set(h) 30 return a 31 } 32 33 func (a *atomic) CrossChainAppRequest( 34 ctx context.Context, 35 chainID ids.ID, 36 requestID uint32, 37 deadline time.Time, 38 msg []byte, 39 ) error { 40 h := a.handler.Get() 41 return h.CrossChainAppRequest( 42 ctx, 43 chainID, 44 requestID, 45 deadline, 46 msg, 47 ) 48 } 49 50 func (a *atomic) CrossChainAppRequestFailed( 51 ctx context.Context, 52 chainID ids.ID, 53 requestID uint32, 54 appErr *common.AppError, 55 ) error { 56 h := a.handler.Get() 57 return h.CrossChainAppRequestFailed( 58 ctx, 59 chainID, 60 requestID, 61 appErr, 62 ) 63 } 64 65 func (a *atomic) CrossChainAppResponse( 66 ctx context.Context, 67 chainID ids.ID, 68 requestID uint32, 69 msg []byte, 70 ) error { 71 h := a.handler.Get() 72 return h.CrossChainAppResponse( 73 ctx, 74 chainID, 75 requestID, 76 msg, 77 ) 78 } 79 80 func (a *atomic) AppRequest( 81 ctx context.Context, 82 nodeID ids.NodeID, 83 requestID uint32, 84 deadline time.Time, 85 msg []byte, 86 ) error { 87 h := a.handler.Get() 88 return h.AppRequest( 89 ctx, 90 nodeID, 91 requestID, 92 deadline, 93 msg, 94 ) 95 } 96 97 func (a *atomic) AppRequestFailed( 98 ctx context.Context, 99 nodeID ids.NodeID, 100 requestID uint32, 101 appErr *common.AppError, 102 ) error { 103 h := a.handler.Get() 104 return h.AppRequestFailed( 105 ctx, 106 nodeID, 107 requestID, 108 appErr, 109 ) 110 } 111 112 func (a *atomic) AppResponse( 113 ctx context.Context, 114 nodeID ids.NodeID, 115 requestID uint32, 116 msg []byte, 117 ) error { 118 h := a.handler.Get() 119 return h.AppResponse( 120 ctx, 121 nodeID, 122 requestID, 123 msg, 124 ) 125 } 126 127 func (a *atomic) AppGossip( 128 ctx context.Context, 129 nodeID ids.NodeID, 130 msg []byte, 131 ) error { 132 h := a.handler.Get() 133 return h.AppGossip( 134 ctx, 135 nodeID, 136 msg, 137 ) 138 } 139 140 func (a *atomic) Set(h common.AppHandler) { 141 a.handler.Set(h) 142 }